It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
7年前关闭。
它说它是“ iOS 5中已弃用”。
如果您想对地理编码进行硬编码的坐标对本身,
使用您的纬度和经度初始化CLLocation位置:
我还想指出,您仍然可以使用
7年前关闭。
它说它是“ 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];
}
}
}
最佳答案
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];
}
});
}];
如果您想对地理编码进行硬编码的坐标对本身,
使用您的纬度和经度初始化CLLocation位置:
CLLocation *aLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
我还想指出,您仍然可以使用
MKReverseGeocoder
。不过,将来的iOS更新可能会将其删除。10-02 14:30