0

MKReverseGeocoder を使用して、緯度/経度の住所を逆にジオコーディングしています。ただし、どのアノテーションのサブタイトルを設定するかを判断するのに苦労しています。それを少し拡張するために、各注釈でリバース ジオコードを呼び出して住所を特定し、字幕テキストを住所に設定したいと考えています。最初の注釈ではなんとかできましたが、2 番目の注釈ではどうすればよいかわかりません。

これが私のコードです:

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

どうすればこれができるか教えてください。

4

1 に答える 1

0

注釈をループしてそれぞれを逆ジオコーディングすることはお勧めしません。リバース ジオコーディング サービスには使用制限があります。Apple は、注釈の選択などのユーザー アクションによってトリガーされた場合にのみ、開発者がリバース ジオコーディング サービスを呼び出すことを推奨しています。

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html%23//apple_ref/occ/cl/MKReverseGeocoder

于 2011-03-06T07:07:33.750 に答える