Last active
November 9, 2016 09:28
-
-
Save milankamilya/73e9b0cbc7ebd791b5316a3eca31eed8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SOURCE: https://developers.google.com/maps/documentation/ios-sdk/urlscheme | |
func startNavigation(dropLocation: CLLocation, startLocation: CLLocation?) { | |
let dCoordinate = dropLocation.coordinate | |
let dLatitude = dCoordinate.latitude | |
let dLogitude = dCoordinate.longitude | |
let baseURL = "comgooglemaps-x-callback://" | |
var navigationURL: String? | |
guard let URL = NSURL(string: baseURL) else { | |
return | |
} | |
let canOpenURL = UIApplication.sharedApplication().canOpenURL(URL) | |
if canOpenURL { | |
guard let appURLScheme = Utility.getCurrentAppURLScheme() else { | |
return | |
} | |
guard let bundleDisplayName = Utility.getBundleDisplayName() else { | |
return | |
} | |
navigationURL = baseURL + | |
"?daddr=\(dLatitude),\(dLogitude)" + | |
//"&saddr=\(sLatitude),\(sLogitude)" + | |
"&mapmode=streetview" + | |
"&views=driving" + | |
"&x-success=\(appURLScheme)://?resume=true" + | |
"&x-source=\(bundleDisplayName)" | |
} else { | |
navigationURL = "https://itunes.apple.com/in/app/google-maps-navigation-transport/id585027354?mt=8" | |
} | |
launchAnAppFromURL(navigationURL) | |
} | |
func launchAnAppFromURL(stringURL: String?) { | |
guard let stringURL = stringURL else { | |
return | |
} | |
if let URLToOpen = NSURL(string: stringURL) { | |
UIApplication.sharedApplication().openURL(URLToOpen) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment