我有一个mapView和Annotation视图,它根据表示物理分支的一系列对象的long / lat来删除区域上的引脚。我有一个标注,提示打开共享应用程序地图,从他们的位置给他们方向..但是,我无法弄清楚如何从分支对象/注释中获取地址并传递它触发CalloutAccessoryControlTapped:
分支对象:
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];
这些注释被添加到地图中,然后当点击标注时,我希望能够将它们推送到具有所选注释(例如,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 :(得分:2)
for(YourMKAnnotationProtocolClass *object in _mapView.selectedAnnotation){
NSLog("%@", object.title); // or you can access other information you've defined
}
答案 1 :(得分:0)
如果你坚持在这里使用AlertView,而不是直接使用calloutAccessoryControlTapped,我只需将选定的Annotation的副标题添加到alertView的meessage中,然后在clickedButtonAtIndex方法中解析它