open Get Direction with multiple stops in google map from using objective c ios

≯℡__Kan透↙ 提交于 2019-12-05 07:42:21

问题


I am using google map sdk and now i want to open get direction in google map where there are multiple stops like i am at Location A and from that i want to go to locations B,C,D i am able to open google map with location A to B but not able to open it for A to B,C,D. How can i do this i tried this

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

回答1:


This is code which is now working fine for get direction. I am answering here so that other will get how to use it

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

}




回答2:


You should use Google Maps URLs that provides universal cross platform syntax to open maps in mobile apps or Google Maps website.

In directions mode, you can specify the origin, destination and multiple waypoints for your route. For more details have a look at the following page:

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

Example of URL:

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

I hope this helps!



来源:https://stackoverflow.com/questions/45770443/open-get-direction-with-multiple-stops-in-google-map-from-using-objective-c-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!