-1

我正在使用谷歌地图 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
4

2 回答 2

3

您应该使用提供通用跨平台语法的Google 地图 URL在移动应用程序或 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

我希望这有帮助!

于 2017-08-21T12:39:46.800 回答
1

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

- (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");
}

}

于 2017-08-22T05:40:38.533 回答