Skip to content

Instantly share code, notes, and snippets.

@anoadragon453
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anoadragon453/9a98c0677728344cbc6a to your computer and use it in GitHub Desktop.
Save anoadragon453/9a98c0677728344cbc6a to your computer and use it in GitHub Desktop.
Reverse Geolocation example in Objective-C for iOS.
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