地图共享应用程序中的 Google 地图方向可提供个性化注释

发布于 2025-01-02 14:51:42 字数 1461 浏览 0 评论 0原文

我创建了一个应用程序,它使用自定义图钉在自定义地图上显示不同的点,并使用公开按钮显示标题和副标题(好吧)。当应用程序启动地图来创建路径然后提供方向时,就会出现问题。要从用户的位置移动,我只需输入 URL“saddr=当前位置”。当我尝试给出用户触摸的相对于触摸的引脚的目的地时,问题就出现了。

- (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)和坐标其他的 4 个要点重复!当用户点击1-2-3或4移动到正确的目的地时该怎么办?

提前致谢! :)

I created an app that displays different points on a custom map with custom pins and showing the title and subtitle with a disclosure button (all right). The problem arises when the app launches maps to create the path and then provide directions. To move from the position of the user I've simply typed in the URL "saddr=Current Position". The problem comes when I try to give the destination that the user has touched, relative to the pin touched.

- (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];

//also mapview.annotation.coordinate.latitude/longitude doesn't work

        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [[UIApplication sharedApplication] openURL:url];
}

I can not figure out how to pass the coordinates of the annotation in the piece of code!

Here's how I said and added the annotation to my 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];

This repeated for 4 main points that have different names (myAnnotation1, 2, 3, 4) and coordinates other! How can I do when the user touches 1-2-3 or 4 to move the right destination?

Thanks in advance! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷荒 2025-01-09 14:51:42

calloutAccessoryControlTapped中,为什么要推送一个空白视图控制器并同时调用openURL

无论如何,注释的坐标位于view.annotation.coordinate中。

因此,纬度为 view.annotation.coordinate.latitude,经度为 view.annotation.coordinate.longitude

此外,在您的 addr 字符串中,坐标之间缺少逗号。

In calloutAccessoryControlTapped, why are you pushing a blank view controller and calling openURL at the same time?

Anyway, the annotation's coordinates are in view.annotation.coordinate.

So the latitude is view.annotation.coordinate.latitude and longitude is view.annotation.coordinate.longitude.

Also, in your addr string, you are missing a comma between the coordinates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文