How to Open Google Map Navigation Url with Direction and Voice in iOS?

我是研究僧i 提交于 2019-12-06 02:18:16

For Google Map You would need to do something like this:-

Use this scheme to request and display directions between two locations. You can also specify the transportation mode.

Parameters saddr: Sets the starting point for directions searches. This can be a latitude,longitude or a query formatted address. If it is a query string that returns more than one result, the first result will be selected. If the value is left blank, then the user’s current location will be used. daddr: Sets the end point for directions searches. Has the same format and behavior as saddr. directionsmode: Method of transportation. Can be set to: driving, transit, bicycling or walking.

An example URL is below to display transit directions between Google NYC and JFK Airport:

comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit

Some additional example are below:

"comgooglemaps://?saddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&daddr=Google+Inc,+345+Spear+Street,+San+Francisco,+CA&center=37.422185,-122.083898&zoom=10"

"comgooglemaps://?saddr=2025+Garcia+Ave,+Mountain+View,+CA,+USA&daddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA,+United+States&center=37.423725,-122.0877&directionsmode=walking&zoom=17"

Refer to:

https://developers.google.com/maps/documentation/ios/urlscheme

For Apple Map do like this:- The following examples show the strings you would use to provide driving directions between San Francisco and Cupertino:

"http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino

Refer:-

"https://developer.apple.com/library/iad/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf"

This works for me, only issue i can see with your query is accurate lat long values(Those looks to be a degree latitude longitude value but passed as a decimal latitude longitude value.

Example Route from Downey to Los Angles NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/? daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",34.0522300,-118.2436800,33.9400100,-118.1325700];

But for some of the directions it does not work and shows Directions not available

you can use the following code; it'll appear the selected location with drop annotation; and from google app you can navigate

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
  NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&q=%f,%f",mosqueLocation.latitude,mosqueLocation.longitude, mosqueLocation.latitude,mosqueLocation.longitude]];
  [[UIApplication sharedApplication] openURL:url];
} else {
  NSLog(@"Can't use comgooglemaps://");
}

enjoy!!!!

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