1

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.

Richard Topchii
  • 7,075
  • 8
  • 48
  • 115

2 Answers2

1

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
kira4ka
  • 26
  • 1
  • 5
  • Note that the Google's API recommends to use `/maps/search`: [Developer Guide | Maps URLs](https://developers.google.com/maps/documentation/urls/guide) – aloisdg Jan 21 '19 at 10:43
  • @aloisdg search is ok when you need to show a Pin of a specific location. Direction is used for a little bit different purpose. But both can be adjusted to the final scope. – kira4ka Jan 21 '19 at 11:09
0

Try this: Right click on info.plist file and select open Source Code. Just right below <dict> add the following lines and you are good to go!

<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
</array>
Sanket Ray
  • 1,071
  • 1
  • 15
  • 24
  • Hi Sanket, it seems to be an issue with the beta release of the iOS, not the way I'm constructing the URL. Even the official example doesn't work. – Richard Topchii Jul 04 '18 at 23:23