在Google地图中使用目标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地图url在移动应用或Google地图网站中打开地图。

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

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

url示例:

https://www.google.com/maps/dir/?api=1&origin=18.518205,73.857431&destination=18.518205,73.857431&waypoints=18.518205,73.857431|18.552248,73.901596|18.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"); } 

}