iosswiftgoogle-mapsdeep-linkingapplinks

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://")
}

Solution

  • 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.