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

时间:2011-01-05 21:22:34

标签: google-maps ios map-directions

截至目前,我已使用以下代码从我的应用中成功生成使用地图应用的路线:

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 个答案:

答案 0 :(得分:27)

嗯,我想在问之前我应该​​更好地搜索一下!

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

这很有趣,因为Apple说他们只支持一些谷歌地图参数,不包括这个参数,但它实际上似乎有效!

有关Google地图参数的详细信息:http://mapki.com/wiki/Google_Map_Parameters
有关iOS应用的地图链接的详细信息:http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html