MKReverseGeocoder“在iOS 5中已弃用" [英] MKReverseGeocoder "deprecated in iOS 5"

查看:80
本文介绍了MKReverseGeocoder“在iOS 5中已弃用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它说它在iOS 5中已弃用".

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



                       }
            }
 }

推荐答案

MKReverseGeocoder在iOS4之后的所有固件中均已弃用.这只是意味着现在使用过时的类已经过时了,皱着眉头.改为使用CLGeocoder

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

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

Initialize a CLLocation location with your latitude and longitude:

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

我还想指出,您仍然可以使用MKReverseGeocoder.不过,可能会在将来的iOS更新中将其删除.

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

这篇关于MKReverseGeocoder“在iOS 5中已弃用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆