Search code examples
iosgoogle-mapsurldeep-linkingopenurl

Unable to launch native Google Maps within the iOS app - Safari opens instead


I'm having trouble launching a Google Maps app from within the iPhone app. While the app is installed on device, the code launches a Web version of the Google Maps in Safari. On the other hand, Apple Maps native app launches successfully.

Here is the code I'm using:

@IBAction func openMap(_ sender: Any) {
  let lat: Double = -37.8218956215849
  let long: Double = 144.9599325656891

  let appleString = "https://maps.apple.com/?daddr=\(lat),\(long)" // Apple Maps - successfully launches an app
  let googleString = "https://www.google.com/maps/dir/?api=1&destination=\(lat)%2C\(long)" // Google Maps - launches a Web version
  let selectedString: String = googleString // Change accordingly
  let url = URL(string: selectedString)!
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

I suppose, the problem is ridiculously simple, however I still haven't figured out how to fix it.

Update

Even the Google's example doesn't work on iOS 12 Beta 2: https://developers.google.com/maps/documentation/urls/ios-urlscheme, the issue might be linked with the usage of the Beta software.


Solution

  • This issue seems to be fixed on last iOS release (12.1.2). And now the following link work on iPhone:

    https://www.google.com/maps/dir/Current+Location/51.5230369,-0.08225500000003194
    

    As alternative solution to /dir api that works on iOs you can use /search :

    https://www.google.com/maps/search/?api=1&query={your_lat},{your_lon}
    
    https://www.google.com/maps/search/?api=1&query=28.6139,77.2090