使用目标 C iOS 打开谷歌地图中具有多个停靠点的获取方向



我正在使用谷歌地图 SDK,现在我想在谷歌地图中打开获取方向,那里有多个站点,就像我在位置 A 一样,我想去位置 B,C,D 我可以打开带有位置 A 到 B 的谷歌地图,但无法打开A 到 B的地图C,D. 我怎么能做到这一点,我试过这个

NSString *str1 =[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@&waypoints=%@&key=%@",originString,destinationString,strWayPoints,GOOGLE_API_KEY];
if([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str1]];
}
//str1 =
http://maps.google.com/?saddr=18.518205,73.857431&daddr=18.518205,73.857431&waypoints=via:18.518205,73.857431|via:18.552248,73.901596|via:18.629764,73.934685&key=MYKEY

您应该使用提供通用跨平台语法的 Google 地图网址在移动应用或 Google 地图网站中打开地图。

在方向模式下,您可以为路线指定起点、目的地和多个航点。有关更多详细信息,请查看以下页面:

https://developers.google.com/maps/documentation/urls/guide#directions-action

网址示例:

https://www.google.com/maps/dir/?api=1&origin=18.518205,73.857431&destination=18.518205,73.857431&waypoints=18.518205,73.857431%7C18.552248,73.901596%7C18.629764,73.934685

我希望这有帮助!

这是现在可以正常工作的代码,用于获取方向。我在这里回答,以便其他人了解如何使用它

- (IBAction)onClickNavigate:(id)sender {
NSString *strWayPoints = [NSString stringWithFormat:@"%f,%f", [[destLatArray objectAtIndex:0] doubleValue], [[destLongArray objectAtIndex:0] doubleValue]];
for(int j=0;j<destLatArray.count;j++){
if(j > 0)
strWayPoints = [NSString stringWithFormat:@"%@|%f,%f", strWayPoints, [[destLatArray objectAtIndex:j] doubleValue], [[destLongArray objectAtIndex:j] doubleValue]];
}
NSString *originString = [NSString stringWithFormat:@"%f,%f",[sourceLat doubleValue], [sourceLong doubleValue]];
NSString *destinationString = [NSString stringWithFormat:@"%f,%f", [[destLatArray objectAtIndex:0] doubleValue], [[destLongArray objectAtIndex:0] doubleValue]];
NSString *str = [NSString stringWithFormat:@"https://www.google.com/maps/dir/?api=1&origin=%@&destination=%@&waypoints=%@",originString,destinationString,strWayPoints];
if([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
else
{
NSLog(@"You haven't installed the google map");
}

}

最新更新