I read around the Internet but couldn't find a legit answer. I need to open Google Maps when the user clicks a button to show directions. Start and destination must be automatically filled.
How can I achieve this in Swift?
If anyone has a solution, please provide me with a sample code. The start is always going to be the user's current location.
OK I found the answer myself.
If you want to show directions from the user's current location, leave the field saddr
blank and in the field daddr
you can enter the destination coordinates.
This is how I did it
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) { UIApplication.sharedApplication().openURL(NSURL(string: "comgooglemaps://?saddr=&daddr=\(place.latitude),\(place.longitude)&directionsmode=driving")!) } else { NSLog("Can't use comgooglemaps://"); } }
for any further queries you can refer to this link Google Map URL Scheme
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With