MKReverseGeocoder"在iOS 5中弃用"

use*_*256 0 iphone xcode mkreversegeocoder ios

它说它"在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];



                       }
            }
 }
Run Code Online (Sandbox Code Playgroud)

Imi*_*rak 14

MKReverseGeocoder在iOS4之后的所有固件中都不推荐使用.这只是意味着它现在已经过时并且不满意使用过时的类.CLGeocoder改为使用,如下所示:

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

                           }

     });

}];
Run Code Online (Sandbox Code Playgroud)

如果你想反转地理编码一个硬编码坐标perse -

使用您的纬度和经度初始化CLLocation位置:

    CLLocation *aLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
Run Code Online (Sandbox Code Playgroud)

我还想指出你仍然可以使用MKReverseGeocoder.它可能会在未来的iOS更新中删除.