【发布时间】:2011-01-25 18:59:20
【问题描述】:
我有一个 mapView 和 Annotation 视图,它根据代表物理分支的一系列对象的长/纬度在区域上放置图钉。我有一个注释的标注,提示打开共享应用程序地图以从他们的位置向他们提供方向。但是,我不知道如何从分支对象/注释中获取地址并在何时传递它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];
这些注释被添加到地图中,然后当标注被点击时,我希望能够将它们推送到带有所选注释(例如公司)副标题的地图应用程序。
- (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 的内存地址。那么我怎样才能从中获取对象呢?
【问题讨论】:
标签: iphone annotations mapkit