xcode MKReverseGeocoder“在 iOS 5 中已弃用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11832150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MKReverseGeocoder "deprecated in iOS 5"
提问by user1555256
It say it is "deprecated in iOS 5".
它说它“在 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];
}
}
}
回答by Imirak
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:
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];
}
});
}];
If you want to reverse geocode a hardcoded pair of coordinates perse --
如果你想对一对硬编码的坐标进行反向地理编码——
Initialize a CLLocation location with your latitude and longitude:
使用您的纬度和经度初始化 CLLocation 位置:
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.
我还想指出,您仍然可以使用MKReverseGeocoder
. 不过,它可能会随着未来的 iOS 更新而被删除。
回答by Yusuf X
I don't know if this answers your tacit question, but the documentationsays to use CLGeocoderinstead.
我不知道这是否回答了您的默认问题,但文档说要改用CLGeocoder。