1

我有一个显示 MapView 的简单应用程序。当用户在地图视图上滚动或更改缩放位置时,我想显示位于地图中心的国家名称。

所以我这样做:

- (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]);
}

regionDidChangeAnimated 方法仅在视图完成滚动时调用,因此每秒调用次数不会超过 1 次。

有时,我会出现“无法完成操作。(PBRequesterErrorDomain 错误 6001。)”错误,因此无法显示国家/地区名称。稍微移动一下地图视图可以解决问题,以便显示国家/地区。

如何确保每次用户更改地图视图显示时都能显示国家名称?

我读过那篇文章,但这没有帮助。

4

1 回答 1

2

您可以捕获该错误,并在 Google 不合作时尝试其他 rev 地理编码服务,例如Yahoo Placefinder 。

于 2011-07-16T23:34:35.237 回答