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

google-mapsiosmapkit

i am newbie in iOS I want to make an app that contain map kit navigation.i want to open navigation url of google map if user device have Google map application. if it is not contain then i want to open Apple map Here i write a code for like as

 -(IBAction)navigationButtonPressed:(id)sender
 {
if ([[UIApplication sharedApplication] canOpenURL:
     [NSURL URLWithString:@"comgooglemaps://"]])
{
    NSString *urlString=[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&zoom=14&views=traffic",self.latitude,self.longitude];
    [[UIApplication sharedApplication] openURL:
     [NSURL URLWithString:urlString]];
}
else
{
    NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?ll=%f,%f",self.latitude,self.longitude];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
}

But here i want to open google map or apple map with turn by turn direction between User current location and Selected Location how it is Possible Please Give me Solution For this.

Best Solution

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

enter image description here

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];

enter image description here

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

enter image description here

Related Question