问题
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];
}
}
}
回答1:
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 --
Initialize a CLLocation location with your latitude and longitude:
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.
回答2:
I don't know if this answers your tacit question, but the documentation says to use CLGeocoder instead.
来源:https://stackoverflow.com/questions/11832150/mkreversegeocoder-deprecated-in-ios-5