我如何使用地图方向应用程序



我有一个在MapView上显示位置的应用程序,我想使用iPhone上的"方向"应用程序从我的当前位置获取特定位置的方向。我该怎么做?

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

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

要做到这一点,你需要编码如下:

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

其中sadr是起始地址(在这种情况下是lat,lon对),daddr是目的地址。

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

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

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

最新更新