我创建了一个应用程序,可以在自定义地图上显示不同的点,使用自定义图钉,并使用公开按钮显示标题和副标题(好吧)。当应用程序启动地图来创建路径,然后提供方向时,问题就出现了。要从用户的位置移动,我只需键入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];
}我不知道如何在这段代码中传递注释的坐标!
下面是我如何将注释添加到我的视图中
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)和坐标other的4个主要点重复执行!当用户触摸1-2-3或4来移动正确的目的地时,我该怎么做?
提前感谢!:)
发布于 2012-02-04 23:53:26
在calloutAccessoryControlTapped中,为什么在推送一个空白视图控制器的同时,还要调用openURL?
不管怎样,注释的坐标是view.annotation.coordinate格式的。
所以纬度是view.annotation.coordinate.latitude,经度是view.annotation.coordinate.longitude。
此外,在addr字符串中,坐标之间缺少逗号。
https://stackoverflow.com/questions/9141776
复制相似问题