Last active
August 29, 2015 14:24
-
-
Save anoadragon453/9a98c0677728344cbc6a to your computer and use it in GitHub Desktop.
Reverse Geolocation example in Objective-C for iOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLGeocoder *geocoder = [CLGeocoder new]; | |
CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:21.1700 | |
longitude:72.8300]; | |
[geocoder reverseGeocodeLocation:newLocation | |
completionHandler:^(NSArray *placemarks, NSError *error) { | |
if (error) { | |
NSLog(@"Geocode failed with error: %@", error); | |
return; // Request failed, log error | |
} | |
// Check if any placemarks were found | |
if (placemarks && placemarks.count > 0) | |
{ | |
CLPlacemark *placemark = placemarks[0]; | |
// Dictionary containing address information | |
NSDictionary *addressDictionary = | |
placemark.addressDictionary; | |
// Extract address information | |
NSLog(@"%@ ", addressDictionary); | |
NSString *address = [addressDictionary | |
objectForKey:(NSString *)kABPersonAddressStreetKey]; | |
NSString *city = [addressDictionary | |
objectForKey:(NSString *)kABPersonAddressCityKey]; | |
NSString *state = [addressDictionary | |
objectForKey:(NSString *)kABPersonAddressStateKey]; | |
NSString *zip = [addressDictionary | |
objectForKey:(NSString *)kABPersonAddressZIPKey]; | |
NSLog(@"%@ %@ %@ %@", address,city, state, zip); | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment