CoreLocation framework of iOS provides method for finding address of a location using its latitude and longitude (also known as ReverseGeocoding). Following code snippet explains how to use it :
CLLocation *location = targetlocation;
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"placemark.ISOcountryCode =%@",placemark.ISOcountryCode);
NSLog(@"placemark.country =%@",placemark.country);
NSLog(@"placemark.postalCode =%@",placemark.postalCode);
NSLog(@"placemark.administrativeArea =%@",placemark.administrativeArea);
NSLog(@"lat %f long %f",placemark.location.coordinate.latitude,placemark.location.coordinate.longitude);
NSLog(@"placemark.name =%@",placemark.name);
NSLog(@"placemark.locality =%@",placemark.locality);
NSLog(@"placemark.Thoroughfare =%@",placemark.thoroughfare);
NSLog(@"placemark.subLocality =%@",placemark.subLocality);
It makes an asynchronous request to fetch the information and the information fetched can be used from within the block. We can get and use different properties of the address of the location as can be seen in the code above.
0 Comment(s)