What is the correct URL format to achieve the following:
- Open a Google Maps app from another app on iOS using the Universal Link.
- Set destination based on two coordinates: latitude and longitude and let the user select the transportation method.
What doesn't work:
let encoded = "https://www.google.com/maps/dir/?api=1&destination=-20.021999%2C57.579075"
let url = URL(string: encoded)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
Also, I've tried to encode the URL using addingPercentEncoding
method:
let string = "https://www.google.com/maps/dir/?api=1&destination=\(lat),\(long)"
let encoded = string.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
let url = URL(string: encoded)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
The result in both cases is the same: "Unsupported link - Google Maps can't open this link"
On the other hand, if I delete the Google Maps app, or try the same code in the simulator, everything works fine and I achieve exactly the result I aim for:
Why does the same link successfully launches the "Web" app, but fails to be recognized by the native app?
String in question:
https://www.google.com/maps/dir/?api=1&destination=-20.021999,57.579075
The guide I'm following: Google Maps Guide