Reputation: 23550
I have a simple app that shows a MapView. When the user scrolls or change the zoom position on the mapview, I want to display the country name that is on the center of the map.
So I do this :
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:self.mapView.centerCoordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
self.countryNameLabel.text = @"";
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
self.countryNameLabel.text = placemark.country;
}
- (void) reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
self.countryNameLabel.text = [error localizedDescription];
NSLog(@"%@", [error localizedDescription]);
}
The regionDidChangeAnimated method is only called when the view has finished scrolling, so no more that 1 call per second.
Sometimes, I have the "The operation couldn’t be completed. (PBRequesterErrorDomain error 6001.)" error so I can't display the country name. Moving a little bit the mapview can solve the problem so the country is displayed.
How can I ensure that I will be able to display the country name each time the user changes the map view display ?
I've read that post but that does not help.
Upvotes: 1
Views: 638
Reputation: 12106
You could trap that error, and try another rev geocoding service, such as Yahoo Placefinder when Google is not cooperating.
Upvotes: 2