Google Maps V2 not working in production with correct key

后端 未结 8 1252
野性不改
野性不改 2020-12-05 23:26

I\'m having major troubles getting Google Maps working in production within an Android app. This is what I am currently getting (the bottom is just ads).

相关标签:
8条回答
  • 2020-12-05 23:34

    In my case, I had entered the wrong package name in Google API's API Manager - Credentials - "Restrict usage to your Android apps". Make sure you enter the correct package name (as in AndroidManifest.xml) and the correct SHA fingerprints (for debug and production).

    0 讨论(0)
  • 2020-12-05 23:37

    Based on the logcat output from your debuggable release build:

    01-11 16:04:54.511  19346-19437/com.mike.mapstest E/Google Maps Android API﹕ Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
    01-11 16:04:54.516  19346-19437/com.mike.mapstest E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
        Ensure that the "Google Maps Android API v2" is enabled.
        Ensure that the following Android Key exists:
        API Key: YOUR_KEY_HERE
        Android Application (<cert_fingerprint>;<package_name>): <SHA1 Removed for this> ;com.mike.mapstest
    

    it would appear that you have not overridden the api key placeholder YOUR_KEY_HERE in the manifest (or separate api keys file, depending on your configuration). Replace that string, wherever it lives, with your actual key and you should be good to go.

    Edit: this tutorial, if it matches your configuration, probably explains why you are only seeing this for release builds:

    Return to Android Studio and paste the API key into the YOUR_KEY_HERE section of the file:

    Note that these steps have enabled Google Maps support for the debug version of the application package. The API key will also need to be added to the google_maps_api.xml file located in MapDemo -> app -> src -> release -> res -> values when the release version of the application is ready to be built.

    0 讨论(0)
  • 2020-12-05 23:38

    In my case, the gray screen was caused by having a custom implementation of HostnameVerifier that was preventing the tiles from being loaded.

    Hope this will help someone else in the future.

    0 讨论(0)
  • 2020-12-05 23:44

    I was having these same issues, and was banging my head against the wall for a few days. I read all the posts about putting the correct key in place. I kept putting the correct key in my google_maps_api.xml file. StKent above mentioned to make sure to overwrite with the actual string in AndroidManifest.xml. This is what fixed it for me.

    What I had when it didn't work: in AndroidManifest.xml:

    <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="@string/google_maps_key" />
    

    and in google_maps_api.xml:

     <string name="google_maps_key"
            templateMergeStrategy="preserve"
            translatable="false">AIza_the actual key</string>
    

    What I changed to for it to work I changed my AndroidManifest.xml to include:

    <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="AIzsa_the actual key" />
    
    0 讨论(0)
  • 2020-12-05 23:44

    debug and production key will be different . If you use debug key for release mode ,you can not view the google map. For release mode , when you change google map key , you should clean the project then export apk.

    you can get more information https://developers.google.com/maps/documentation/android/start

    to get private SHA1 from debug key store

    keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass your_app_password

    to see more

    SHA-1 fingerprint of keystore certificate

    or you can you eclipse tool to generate private SHA1 key using export menu

    0 讨论(0)
  • 2020-12-05 23:45

    Solved, I put on the Manifest the "Key for browser apps (with referers)" instead of the "Key for Android apps (with certificates)" from the Google API Console

    0 讨论(0)
提交回复
热议问题