ios - map 共享应用程序中的谷歌地图方向到个性化注释

标签 ios google-maps annotations mapkit directions

我创建了一个应用程序,它使用自定义图钉在自定义 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/

相关文章:

ios - 这个 block 队列中发生了什么?

javascript - 谷歌地图回调后Angular2双向绑定(bind)停止工作

java - hibernate 定义可能的列值

java - 如果只有 Class<Annotation> 可用,如何传递 Annotation 对象?

ios - 如何确定多个(n)日期时间范围何时相互重叠

iphone - 将 NSURL 与在其获取请求中使用方括号的 PHP Web 服务一起使用

android - 如何在 Google Map Api V2 Android 中搜索?

css - KML 图层光标 CSS - Google Maps API v3

java - 如何将数组作为注释参数传递?

ios - 如何在给定不同排序参数的情况下自动重绘 UITableViewCells