使用iOS地图应用生成步行路线指引

7

目前为止,我使用以下代码从我的应用程序成功地通过 Maps 应用生成方向:

NSString *formattedGroceryAddress = [[NSString stringWithFormat:@"%@",((EnhancedUIActionSheet *)actionSheet).grocery.address] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSString *routeString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",localDataHelper.userLocation.coordinate.latitude,localDataHelper.userLocation.coordinate.longitude,formattedGroceryAddress];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:routeString]];

它会打开适当的 "驾车" 方向指示,但我想默认情况下用 "步行" 方向来打开地图。也许我可以在请求中传递另一个参数来实现这一点。 有人知道怎么做吗?谢谢!
1个回答

27

在询问前,我应该更好地搜索!

您可以将dirflg=w添加到请求中,这将以步行模式启动地图应用程序。

有趣的是,苹果表示他们只支持少数Google Maps参数,不包括这个,但它实际上似乎是有效的!

有关Google Maps参数的更多信息:http://mapki.com/wiki/Google_Map_Parameters
有关来自iOS应用程序的地图链接的更多信息:http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html


嘿兄弟,链接对我有效,但现在我有一个问题,我无法从调用地图应用程序的位置返回到我的应用程序。有什么想法吗? - nikesh
这是苹果文档的有效URL链接:https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html - benLIVE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接