Google maps v2: Authorization failure

为君一笑 提交于 2019-11-28 19:10:52

Activate the Google Maps Android API v2 service in the Google API's console. Also, after making changes do a full reinstall of the app on the device/emulator.

For me help this, if simple: When you work from Android Studio you write your Google API key in file google_maps_api.xml but Android Studio show you only key file for (debug) version in Project Manager. You need place your key in

\app\src\release\res\values\google_maps_api.xml

file too (like you place in place your key in

\app\src\debug\res\values\google_maps_api.xml

)

When you set up your API key, the package name is the value of the package attribute on your manifest, not the application name.

This (com.foo):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.foo"

Not this (com.foo.MyApplication):

<application
    android:name="com.foo.MyApplication"

I had the same problem, but had activated the right api. The problem was that I used the wrong keystore file when getting my SHA1. I used the release keystore, instead I needed to use:

keytool -list -v -keystore debug.keystore

on this file (mac osX location):

~/.android/debug.keystore

That gave me another sha1 that I entered in the google console, and now it works.

Vinod Joshi

Make sure following things:

https://code.google.com/apis/console/?noredirect
Click on Services(Left side panel) -> Enable Google Maps Android API v2

To get your SHA1 key you can use: following command This command will generate keystore

keytool -genkey -v -keystore GoogleMapV2.keystore -alias GoogleMapV2 -keyalg RSA -    keysize 2048 -validity 10000

This command give SHA1 key and other information

keytool -list -v -keystore ~/path/to/GoogleMapV2.keystore -alias GoogleMapV2 -storepass any-password -keypass any-password i.e :

68:1C:74:24:7B:1F:9C:71:76:DD:69:4F:F2:8F

: Your Keys inside <application> </application> tag

<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR KEY" />
<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

Permission outside <application> </application> tag, on the top

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!--
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

NOTE: Don't run App using Eclipse or emulator, Run into real device by creating an apk not using eclipse else would take incorrect debug key.

VkJ

Please ensure your package name is typed correctly in google developer console/credentials/package name. It must be your application top package name eg. com.company.appname not com.company.appname.ui.activity.maps . I followed instructions from https://developers.google.com/maps/documentation/android/start but created Activity in nested package. Google webpage entered nested package name and I had this error.

I have no evidence of this apart from my observation, but it looks like it may take a few minutes before the API key is active once it is set up.

A little patience seemed to work for me!

To Make it clear . If The Map activity shows with no error while debugging your app on the android sdk but it show nothing and give this error when u install the apk :

07-02 03:18:36.467 25914-26028/? E/Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map. 07-02 03:18:36.470 25914-26028/? 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 (;):

The solution will be : placing your key in : \app\src\release\res\values\google_maps_api.xml

as u diid in : \app\src\debug\res\values\google_maps_api.xml

as mentioned here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!