可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
Ensure that the following correspond to what is in the API Console: Package Name: com.company.app
, API Key: AIzaSyC***OsTeo
, Certificate Fingerprint: 4E5285***6BF53ED3
Failed to contact Google servers. Another attempt will be made when connectivity is established.
Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I know there are more then enough questions about this subject.
But I just can't seem to get the maps view to work. The result is an empty maps view (with zoom buttons).
What I've done:
- Downloaded / installed google-play-services
- Added google-play-services.jar
to libs/
- Enabled Google Maps API v2
in code.google.com/apis/console
- Set up the correct permissions
This is how my manifest looks like:
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission
android:name="com.company.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.company.app.permission.MAPS_RECEIVE" />
<application ...>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC***OsTeo" />
</application>
Google APIs console api access looks like this:
Key for Android apps (with certificates)
API key: AIzaSyC***OsTeo
Android apps: 4E:52:85:***6B:F5:3E:D3;com.company.app
Activated on: Jun 18, 2013 11:07 PM
Activated by: my@email.com – you
And some code (which I can't see why this would result in an authorization error):
FragmentManager fragmentManager = super.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
SupportMapFragment fragment = new SupportMapFragment();
fragmentTransaction.replace(R.id.mapContainer, fragment);
fragmentTransaction.commit();
As you can see I get an error saying the package name, api key and certificate fingerprint do not correspond with the google servers. But like I'm writing above, those values do match...
回答1:
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.
回答2:
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
)
回答3:
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"
回答4:
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.
回答5:
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.
回答6:
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
回答7:
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!
回答8:
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