Reverse Geocode in iOS w/ CLGeocoder
If you’re using CLLocationManager to obtain the user’s location, you can add some code in the delegate method to reverse geocode the user’s location…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (curLocation.horizontalAccuracy < 200) // w/in 200 meters { [locMgr stopUpdatingLocation]; NSLog(@"Location: %f %f", curLocation.coordinate.latitude, curLocation.coordinate.longitude); // find a placemark using the found coordinates CLGeocoder *geoCoder = [[CLGeocoder alloc] init]; [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) { if (error) NSLog(@"Error: %@", error); else if (placemarks.count > 0) curPlacemark = [placemarks firstObject]; }]; } } |
Alloc-init a CLGeocoder and call reverseGeocodeLocation: w/ the location passed in (or any location) and a completion handler. I’m storing it in a instance variable to use later. Here’s some code Read more about Reverse Geocode in iOS w/ CLGeocoder[…]