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

白昼怎懂夜的黑 提交于 2019-12-03 21:56:53

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

}

xomena

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!

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