2011-01-25 75 views
1

我有,基於經度/緯度一系列代表物理分支對象的一個​​區域下降銷一個MapView和註解視圖對象屬性。我已經得到了被提示打開共享應用程序映射給他們從他們的位置方向註釋標註..但是,我無法弄清楚如何從分支對象/註釋獲取地址,當它傳遞在CalloutAccessoryControlTapped火災:獲得來自mapView.SelectedAnnotations

科對象:


CLLocationCoordinate2D newCord; 
newCord.latitude = 34.0038; 
newCord.longitude = -84.0965; 
corp = [[LocationwithAnnotation alloc] initWithCoordinate:newCord]; 
corp.mTitle = @"Corp Office"; 
corp.mSubTitle = @"123 Main Street, Duluth GA"; 
[mapView addAnnotation:corp]; 
[corp release]; 

newCord.latitude = 33.0038; 
newCord.longitude = -84.3965; 
uga = [[LocationwithAnnotation alloc] initWithCoordinate:newCord]; 
uga.mTitle = @"uga Office"; 
uga.mSubTitle = @"123 Main Street, Atlanta GA"; 
[mapView addAnnotation:uga]; 
[corp release]; 

這些註釋添加到地圖,那麼當標註被擊中,我希望能夠TP他們推到地圖應用與所選擇的註釋的(CORP,例如)字幕。

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; 
annView.pinColor = MKPinAnnotationColorGreen; 
annView.animatesDrop=TRUE; 
annView.canShowCallout = YES; 
annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
annView.calloutOffset = CGPointMake(-5, 5); 
return annView; 
} 

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
NSLog(@"%@", mapView.selectedAnnotations); 
UIAlertView *alert = [[UIAlertView alloc] 
initWithTitle:@"Directions" 
message:@"Get directions to this branch?" 
delegate:self 
cancelButtonTitle:@"No" 
otherButtonTitles: @"Yes, please", nil]; 
[alert show]; 
[alert release]; 

} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
if (buttonIndex == 1) { 
MKUserLocation *loc = mapView.userLocation.location; 
double latitude = loc.location.coordinate.latitude; 
NSString *lat = [NSString stringWithFormat:@"%f",latitude]; 
double longitude = loc.location.coordinate.longitude; 
NSString *lon = [NSString stringWithFormat:@"%f",longitude]; 
NSString *base = @"http://maps.google.com/maps?"; 
NSString *dest = [@"daddr=" stringByAppendingString: mapView.SelectedAnnotations; // Doesn't work. 

我的NSLog傾銷的唯一的事情就是內存地址SelectedAnnotation ..我怎麼能抓住從該對象?

回答

0

如果你堅持在這裏使用AlertView,而不是直接利用calloutAccessoryControlTapped,我只想補充選定標註的副標題爲alertView的meessage,然後分析在clickedButtonAtIndex方法

2
for(YourMKAnnotationProtocolClass *object in _mapView.selectedAnnotation){ 

     NSLog("%@", object.title); // or you can access other information you've defined 
}