Easiest way of getting reverse geocoded current location from iOS

kamziro picture kamziro · Feb 20, 2011 · Viewed 30.8k times · Source

I saw from another question here : Determine iPhone user's country that it is possible to get the current country the user of the iPhone is in.

And that is quite convenient for many uses. However, would it be possible to go even deeper and infer from iOS (if it has the information) which state or city the user is in as well?

I suppose reverse geocoding services would be the next step if things weren't possible.. Are there even such things as a reverse geocoding service you can hire for your app though?

Answer

fengd picture fengd · Mar 26, 2012

MKReverseGeocoder is deprecated in iOS 5, now it's CLGeocoder

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
   [self.locationManager stopUpdatingLocation];

   CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
   [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
       for (CLPlacemark * placemark in placemarks) {
           .... = [placemark locality];
        }    
    }];
}