0

我有一个在 MapView 上显示位置的应用程序,我想使用 iPhone 上的 Directions APP 从我当前的位置获取特定位置的方向。我怎样才能做到这一点?

4

3 回答 3

1

根据您的问题,我假设您想使用地图应用程序获取路线。

为此,您需要编写如下代码:

NSString *mapsUrl = 
       [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",
        self.mapView.userLocation.location.coordinate.latitude,
        self.mapView.userLocation.location.coordinate.longitude,
        <destination address>];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: [mapsUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]];

其中,saddr 是起始地址(或在这种情况下是 lat、lon 对),而 daddr 是目标地址。

于 2012-01-07T17:10:24.663 回答
1

这是 Jeff 的一篇相当老的帖子:http: //iphonedevelopment.blogspot.com/2009/02/mapping-directions-from-your-app.html

于 2012-01-07T17:05:41.067 回答
0

我以前做过。这基本上比它的价值更麻烦,因为您必须自己实现方向,并且每次地图应用程序添加新功能时,您的应用程序中的方向系统就会变得过时。您真正想要做的是为要在地图应用程序中打开的路线创建一个链接。所有者总是争辩说他们不希望用户不得不离开应用程序,但最终您希望为用户提供最好的实用程序,不幸的是链接到地图应用程序是这里的方法。

您可以像这样链接到地图应用程序:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.google.com/whateveryoururlis"];

于 2012-01-07T17:05:56.633 回答