我正在使用MKReverseGeocoder对纬度/经度地址进行反向地理编码。但是我无法确定要设置哪个Annotation的副标题。为了扩展这一点,我在每个注释上调用反向地理编码来确定地址,然后我想将它们的字幕文本设置为它们的地址。我已经成功完成了第一次注释,但我不确定如何为第二次注释做这件事。
这是我的代码:
- (void)loadAnnotations {
Annotation *annotation1 = [[Annotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(a,b)];
annotation1.title = @"Anno1n";
CLLocation *annoe = [[CLLocation alloc] initWithLatitude:annotation1.coordinate.latitude longitude:annotation1.coordinate.longitude];
CLLocation *usrloc = [[CLLocation alloc] initWithLatitude:mapView.userLocation.coordinate.latitude longitude:mapView.userLocation.coordinate.longitude];
NSLog(@"%.2f km", [annoe distanceFromLocation:usrloc]/1000);
MKReverseGeocoder *geo = [[MKReverseGeocoder alloc] initWithCoordinate:annotation1.coordinate];
[geo setDelegate:self];
[geo start];
[mapView addAnnotation:annotation1];
Annotation *annotation2 = [[Annotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(c,d)];
annotation2.title = @"Anno2";
geo = [[MKReverseGeocoder alloc] initWithCoordinate:annotation2.coordinate];
[geo start];
[mapView addAnnotation:annotation2];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
NSArray *array = [[placemark addressDictionary] objectForKey:@"FormattedAddressLines"];
if (geocoder.coordinate.latitude == mapView.userLocation.coordinate.latitude && geocoder.coordinate.longitude) {
mapView.userLocation.title = @"Current Location";
mapView.userLocation.subtitle = [NSString stringWithFormat:@"%@ %@", [array objectAtIndex:0], [array objectAtIndex:1]];
}
else {
Annotation *annot = (Annotation *)[[mapView annotations] objectAtIndex:1];
[annot setSubtitle:[NSString stringWithFormat:@"%@ %@", [array objectAtIndex:0], [array objectAtIndex:1]]];
//NSLog(@"%@", [placemark addressDictionary]);
}
}
请让我知道如何做到这一点。
答案 0 :(得分:0)
不推荐使用您的注释和反向地理编码。反向地理编码服务有使用限制。 Apple建议开发人员只应在用户操作触发时调用反向地理编码服务,例如选择注释。