2011-03-06 19 views
0

我正在使用MKReverseGeocoder反向地理編碼經度/緯度地址。但是,我無法確定哪個Annotation的字幕將被設置。爲了擴大這一點,我在每個註釋上調用一個反向地址解析來確定地址,然後我想將他們的字幕文本設置爲他們的地址。我設法做了第一次註釋,但我不確定我會如何做第二次註釋。MKReverseGeocoder設置哪個註釋的副標題

這裏是我的代碼:

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

請讓我知道我能做到這一點。

回答