MKReverseGeocoder“在iOS 5中弃用”

时间:2012-08-06 16:20:50

标签: iphone ios xcode mkreversegeocoder

它说它已经在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 个答案:

答案 0 :(得分:14)

在iOS4之后的所有固件中都不推荐使用

MKReverseGeocoder。这只是意味着它现在已经过时并且不满意使用过时的类。请改用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];

                           }

     });

}];

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

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

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

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

答案 1 :(得分:2)

我不知道这是否可以回答您的默认问题,但documentation表示要使用CLGeocoder代替。