我是iOS的新手,我想做一个包含地图工具包导航的应用程序。如果用户设备有谷歌地图应用程序,我想打开谷歌地图的导航网址。如果它不包含,那么我想在这里打开Apple map,我为下面这样写了一段代码
-(IBAction)navigationButtonPressed:(id)sender
{
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]])
{
NSString *urlString=[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&zoom=14&views=traffic",self.latitude,self.longitude];
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:urlString]];
}
else
{
NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?ll=%f,%f",self.latitude,self.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
}但在这里,我想打开谷歌地图或苹果地图,在用户的当前位置和选定的位置之间依次转向方向,这是如何可能的,请给我解决方案。
发布于 2015-02-12 14:25:49
对于谷歌地图,你需要这样做:
使用此方案可以请求和显示两个位置之间的方向。您还可以指定运输模式。
Parameters saddr:设置方向搜索的起点。这可以是纬度、经度或查询格式的地址。如果是返回多个结果的查询字符串,则选择第一个结果。如果将该值留空,则将使用用户的当前位置。daddr:设置方向搜索的终点。具有与saddr相同的格式和行为。方向模式:交通方式。可以设置为:驾驶、交通、骑自行车或步行。
下面是一个示例URL,用于显示Google NYC和JFK机场之间的交通路线:
comgooglemaps://?saddr= +NY&daddr=John+F.+Kennedy+International+Airport,+公司,+8th+Avenue,+New+York,Google +Van+Wyck+Expressway,+牙买加,+New+York&directionsmode=transit

下面是一些额外的示例:
"comgooglemaps://?saddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&daddr=Google+Inc,+345+Spear+Street,+San+Francisco,+CA¢er=37.422185,-122.083898&zoom=10“
“搜索地图://?saddr=2025+Garcia+Ave,+Mountain+View,+CA,+USA&daddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA,+United+States¢er=37.423725,-122.0877&directionsmode=walking&zoom=17”
请参阅
https://developers.google.com/maps/documentation/ios/urlscheme
对于Apple Map,这样做:-以下示例显示了您将用于提供旧金山和库比蒂诺之间的驾驶方向的字符串:
“http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino”
Refer:-
这对我来说很有效,我在您查询中看到的唯一问题是lat值的准确性(这些值看起来是度纬度经度值,但它是作为十进制纬度经度值传递的。
从唐尼到洛杉矶的示例路线NSString *string = [NSString字符串格式:@“http://maps.apple.com/?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",34.0522300,-118.2436800,33.9400100,-1.6F];


但对于某些方向,它不起作用,并显示不可用的方向


发布于 2015-04-14 05:18:22
您可以使用以下代码;它将显示带有拖放注释的选定位置;并且您可以在google应用程序中导航
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&q=%f,%f",mosqueLocation.latitude,mosqueLocation.longitude, mosqueLocation.latitude,mosqueLocation.longitude]];
[[UIApplication sharedApplication] openURL:url];
} else {
NSLog(@"Can't use comgooglemaps://");
}享受吧!
https://stackoverflow.com/questions/28469570
复制相似问题