Google Maps API V2 - always get authentication err

2019-01-26 19:39发布

问题:

I found lots of questions regarding this - and I am almost ashamed to ask it myself.

But no matter how hard I try, I simple do not get the Maps API running at all!

Not with the demo project, com.example.mapdemo, not with my own project.

I definitely have my debug.keystore SHA1 fingerprint registered, now for both my app and com.example - I also tried the browser API key where everybody says that would work, too.

BUT NO.

I always get:

06-16 11:21:29.860: E/Google Maps Android API(2382): Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.

I am getting REALLY, REALLY mad at this. How is it possible to NOT completely and thoroughly describe this matter so that people that are otherwise able to program Android apps, can follow and succeed??

HOW?

Could anybody please tell me what else could be wrong?

Add-on: I set up everything exactly according to the specs, got my key from my debug.keystore, tried it with com.example for the maps demo, with my own package for my app. Does not work. Plus: that silly empty window. How on earth is that gonna work... :-(

回答1:

Assuming

  • you are trying this on a device that has access to Google Play Services
  • you have linked your project with the Google Play Services library
  • you have setup the necessary permissions like this:

snippet from manifest:

<!-- Specify the correct minSDK and targetSDK versions. -->
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<!-- Google Maps related permissions -->
<permission
    android:name="com.ecs.google.maps.v2.actionbarsherlock.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />

<!-- Network connectivity permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- Access Google based webservices -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
  • you have setup the map key like this :

  • you have put the meta-data tag inside the application tag

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyA_u1faIXRhx_Q7NafFbrhQJEerl6UUbPY" />
    
  • you made sure that you are building the APK with the correct keystore (corresponding to the one defined in the API console).

  • you removed and redeployed your application completely after checking / updating these steps you should be good to go.

From my experience I was able to follow the instructions on Google Maps Android API v2 Getting started, but I do recall having to completely undeploy and redeploy the app again after playing around with the API keys / permissions.

On what device are you running ?



回答2:

I am also having the same issue and know I kinda know what causes the problem ( not the solution to it though -yet- )

Try to run your app of other phone than your HTC One. Because I have the issue with my HTC One but when I run it on my S3, it runs perfectly.

Try and let me know please

EDIT

I solved it. But not sure what was the exact solution but here what I did as steps: 1- I displayed the developers options in the phone settings use the 7 times clicks in 4.2 OS 2- Allowed Mock Location 3- Selected my app in the "select debug app" 4- uninstalled my app 5- re-installed it 6- run it and waited for 30 seconds then the maps showed

Hope this helps



回答3:

I was having the same problem , then i found out that i had made a simple mistake please verify whether you have turned on "Google Maps Android API v2" in services catagory of google api console . I had turned on the wrong one it never worked for me , but now it works, hope this helps. https://code.google.com/apis/console



回答4:

Even I was facing the same issue for days. I simply uninstalled the app from settings, reinstalled it and magically it worked.



回答5:

I had got same issue. After checking 20th time the steps from ddewaele's answer, turning on the Maps V2 android in Google's API console, I have restarted my phone, waited ~15s for data to download and all works like a charm. Uninstalling application was not enough to get it working. Just leaving info for other map using devs on the edge.



回答6:

i have same problem i spent two weeks to get a solution at last i got it. just remove key from res/values/google_maps_api.c and repalace it by new key follow below steps you will get a new key.

1> Find SHA1 by Using that command in command prompt:

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

2> Get Package name from android manifest and use finger print of SHA1 for create an new api key 


3> copy created key and past it in res/values/google_maps_api.xml and also past in android manifest 

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">Paste Here New Api</string>
</resources>

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="Paste Key Here" />


回答7:

I know it is an old thread but it was edited few months ago, and i just run into the same problem. Since the cause of my version of the problem was a bit different i'll add it here. I had checked that all the previously cited conditions where true but it was still giving the same error.

After some hours of randomly trying stuff i finally found out that the xml string translation manager of Android Studio had created a new string with the same identifier of the google api key (which is by default stored in a different xml file from the other strings). This new string resource was indeed empty and conficlting with the true key. It was sufficient to delete it to solve the problem.