This is how I do it in Objective C...I always try the Waze Map first, because to be honest, it's awesome sauce, I added the PLIST file permissions at the end:
- (IBAction)getDirectionsAction:(id)sender {
NSURL *googleURL = [[NSURL alloc]
initWithString:[NSString stringWithFormat:@"comgooglemaps://?daddr=%@", @"44.294349,-70.326973"]];
NSURL *googleWebURL =
[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.maps.google.com/maps?daddr=%@",
@"44.294349,-70.326973"]];
NSURL *appleURL = [NSURL URLWithString:@"http://maps.apple.com/?daddr=311+East+Buckfield+Road+Buckfield+Maine"];
NSURL *wazeURL = [NSURL URLWithString:@"waze://?ll=44.294349,-70.326973&navigate=yes"];
// Lets try the Waze app first, cuz we like that one the most
if ([[UIApplication sharedApplication] canOpenURL:wazeURL]) {
[[UIApplication sharedApplication] openURL:wazeURL
options:@{}
completionHandler:^(BOOL success){
}];
return;
}
// Lets try the Apple Maps app second (great success rate)
if ([[UIApplication sharedApplication] canOpenURL:appleURL]) {
[[UIApplication sharedApplication] openURL:appleURL
options:@{}
completionHandler:^(BOOL success){
}];
return;
}
// If those 2 are unsuccessful, let's try the Google Maps app
if ([[UIApplication sharedApplication] canOpenURL:googleURL]) {
[[UIApplication sharedApplication] openURL:googleURL
options:@{}
completionHandler:^(BOOL success){
}];
return;
}
// Uh, oh...Well, then lets launch it from the web then.
else {
[[UIApplication sharedApplication] openURL:googleWebURL
options:@{}
completionHandler:^(BOOL success){
}];
}
}
FOR PLIST FILE
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>http://maps.apple.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>http://maps.google.com/</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
</dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
<string>comgooglemaps</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>For Use for directions</string>