Eric Chong
Eric Chong

Reputation: 505

Can't open google map

I use the following swift code and but it print "Can't use comgooglemaps://" everytime. I test it in real iphone7 and google map app has been installed. Please kindly help.

if UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
   UIApplication.shared.open(URL(string:"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")!)
} else {
   print("Can't use comgooglemaps://")
}

Upvotes: 2

Views: 1964

Answers (2)

user3826696
user3826696

Reputation: 1135

Add to your Custom IOS Target Properties

Queried URL Schemes -> comgooglemaps

enter image description here

Upvotes: 0

mugx
mugx

Reputation: 10105

It's mandatory to define the key LSApplicationQueriesSchemes, hence inside your Info.plist you should have the following:

enter image description here

If you want to change it manually you may add this:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
</array>

You may check the official documentation at Step 7: Declare the URL schemes used by the API:

Beginning with iOS 9 and Xcode 7, apps must declare the URL schemes that they intend to open, by specifying the schemes in the app's Info.plist file. The Google Maps SDK for iOS opens the Google Maps mobile app when the user clicks the Google logo on the map, and your app therefore needs to declare the relevant URL schemes.

Upvotes: 8

Related Questions