2011-01-25 72 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 
}