MKReverseGeocoder "deprecated in iOS 5"

6.4k Views Asked by At

It say it is "deprecated in iOS 5".

- (void)viewDidLoad {
    [super viewDidLoad];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    [geocoder reverseGeocodeLocation:self.locationManager.location // You can pass aLocation here instead
                   completionHandler:^(NSArray *placemarks, NSError *error) {

                 dispatch_async(dispatch_get_main_queue() , ^ {
                           // do stuff with placemarks on the main thread

                           CLPlacemark *place = [placemarks objectAtIndex:0];

                           NSString *zipString = [place.addressDictionary valueForKey:@"ZIP"];

                           [self performSelectorInBackground:@selector(showWeatherFor:) withObject:zipString];



                       }
            }
 }
2

There are 2 best solutions below

38
On BEST ANSWER

MKReverseGeocoder is deprecated in all firmwares after iOS4. This just means that it is now obsolete and frowned upon to be using the outdated class. Use CLGeocoder instead, like so:

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

        [geocoder reverseGeocodeLocation:self.locationManager.location // You can pass aLocation here instead 
                       completionHandler:^(NSArray *placemarks, NSError *error) {

                           dispatch_async(dispatch_get_main_queue(),^ {
                               // do stuff with placemarks on the main thread

                           if (placemarks.count == 1) {

                           CLPlacemark *place = [placemarks objectAtIndex:0];


                           NSString *zipString = [place.addressDictionary valueForKey:@"ZIP"];

                           [self performSelectorInBackground:@selector(showWeatherFor:) withObject:zipString];

                           }

     });

}];

If you want to reverse geocode a hardcoded pair of coordinates perse --

Initialize a CLLocation location with your latitude and longitude:

    CLLocation *aLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];

I also want to point out that you can still use MKReverseGeocoder. It may be removed with future iOS updates though.

2
On

I don't know if this answers your tacit question, but the documentation says to use CLGeocoder instead.