我创建了一个应用程序,它使用自定义图钉在自定义 map 上显示不同的点,并使用公开按钮显示标题和副标题(好吧)。当应用程序启动 map 以创建路径然后提供方向时,就会出现问题。要离开用户的位置,我只需输入 URL“saddr=Current Position”。当我尝试给出用户触摸的目的地(相对于触摸的引脚)时,问题就来了。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f%1.6f&saddr=Posizione Attuale", mapView.annotations.coordinate.latitude mapView.annotations.coordinate.longitude];
//mapview.annotation.coordinate.latitude/longitude 也不起作用
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
我想不通如何在这段代码中传递注释的坐标!
这是我所说的并将注释添加到我的 View 中的方式
NSMutableArray* annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 45.7;
theCoordinate1.longitude = 7.64;
myAnnotation* myAnnotation1=[[myAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate1;
myAnnotation1.title=@"Pippo";
myAnnotation1.subtitle=@"Ufficio";
[myMapView addAnnotation:myAnnotation1];
这对具有不同名称(myAnnotation1、2、3、4)和其他坐标的 4 个主要点重复!当用户触摸 1-2-3 或 4 以移动正确的目的地时,我该怎么办?
提前致谢! :)
最佳答案
在 calloutAccessoryControlTapped
中,为什么要推送空白 View Controller 并同时调用 openURL
?
无论如何,注释的坐标在 view.annotation.coordinate
中。
所以纬度是view.annotation.coordinate.latitude
,经度是view.annotation.coordinate.longitude
。
此外,在您的 addr
字符串中,您缺少坐标之间的逗号。
关于ios - map 共享应用程序中的谷歌地图方向到个性化注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9141776/