MKReverseGeocoder “deprecated in iOS 5” [closed]

岁酱吖の 提交于 2019-12-23 04:33:57

问题


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];



                       }
            }
 }

回答1:


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:


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



来源:https://stackoverflow.com/questions/11832150/mkreversegeocoder-deprecated-in-ios-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!