LBLocation class will help you get the user location very easy and make forward and reverse geocoding.
Import CoreLocation, MapKit
and AddressBookUI
frameworks.
Create the LBLocation object using initWithLocationUpdateBlock:
.
The completionBlock will be called with the CLLocation
value or, in case of error the completionBlock is called with a nil
value.
The LBLocation class uses NSNotificationCenter
and calls the startLocationServices
method when the UIApplicationDidBecomeActiveNotification
notification is received. It also calls the stopLocationServices
when the UIApplicationWillResignActiveNotification
notification is received.
__weak ViewController *weakSelf = self;
self.location = [[LBLocation alloc] initWithLocationUpdateBlock:^(CLLocation *location) {
weakSelf.myLocation = location;
}];
You can use reverseGeocodeCurrentLocationWithCompletionBlock:
and reverseGeocodeLocation:completionBlock:
methods and the completion block will be called with a CLPlacemark
object or nil
value.
You can get a string with the address from the CLPlacemark object using the addressStringFromPlacemark:
method.
You can use the geocodeAddressString:completionBlock:
and geocodeAddressDictionary:completionBlock:
methods,pass a string or dictionary with the address and the completion block will be called with a CLLocation
object or nil
value.
This content is released under the MIT License https://github.com/lucianboboc/LBLocation/blob/master/LICENSE.md
Enjoy!