Google Maps Android API:授权失败.确保"Google Maps Android API v2"已启用.确保以下Android密钥存在 [英] Google Maps Android API: Authorization failure. Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists

本文介绍了Google Maps Android API:授权失败.确保"Google Maps Android API v2"已启用.确保以下Android密钥存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

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.
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: [The key...]
    Android Application (<cert_fingerprint>;<package_name>):

这是我看到的,而不是地图正常工作:

Instead of the map working correctly, this is what I see:

在我的app/build.gradle中,我有这个:

implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.android.gms:play-services-awareness:16.0.0'
implementation 'com.google.android.gms:play-services-cast:16.2.0'
implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'

play-services-location是我需要的Google地图,对吗?我在 https://developers.google.com/android/guides/setup查看列表,并且我认为Google Location and Activity Recognition - com.google.android.gms:play-services-location:16.0.0是Google Maps所需要的.这是正确的吗?

play-services-location is what I need for the Google Maps, correct? I was looking at the list at https://developers.google.com/android/guides/setup and I assume that Google Location and Activity Recognition - com.google.android.gms:play-services-location:16.0.0 is what I need for Google Maps. Is this correct?

更新1:我已经启用了适用于Android的Maps SDK:

UPDATE 1: I already have Maps SDK for Android enabled:

错误提示:Ensure that the "Google Maps Android API v2" is enabled..是指我在 UPDATE 1 的屏幕快照中显示的Maps SDK for Android吗?

The error says: Ensure that the "Google Maps Android API v2" is enabled.. Is it referring to the Maps SDK for Android that I am showing in the screenshot in this UPDATE 1?

更新2:我已启用Maps SDK for Android:

当我单击MANAGE按钮时,可以转到此部分以配置在 UPDATE 1 中显示的凭据.

When I click the MANAGE button, I can go to the section to configure credentials that I showed in UPDATE 1.

更新3:我在模拟器上看到所有版本的Android上正确显示的地图.但是在物理设备上,地图永远不会显示.在实体手机上运行该应用程序时,我看到了Google徽标和红色气球,但现在看到了地图.只有在仿真器上,所有东西都可以工作.有什么想法吗?

UPDATE 3: I see the Map displayed correctly on all versions of Android on the Emulator. But on physical devices, the map never shows up. I see the Google logo and the red balloon, but now the map when I run the app on physical phones. Only on the Emulator everything works. Any ideas why?

更新4:参见我的解决方案,网址为 https://stackoverflow.com/a/56307654/4242086 .

UPDATE 4: See my solution at https://stackoverflow.com/a/56307654/4242086.

推荐答案

我遵循了本教程,并能够对其进行修复: https://www.youtube.com/watch?v=sJBlQv6IptQ .该视频引用了本教程: http://ramsandroid4all.blogspot.com/2016/01/google-maps-android-example-in-android.html .

I followed this tutorial and I was able to fix it: https://www.youtube.com/watch?v=sJBlQv6IptQ. The video makes references to this tutorial: http://ramsandroid4all.blogspot.com/2016/01/google-maps-android-example-in-android.html.

就我而言,我要做的是在 https://console.developers上创建一个新项目. google.com/.我将Android apps用于Application restrictions:

In my case, what I did was to create a new project at https://console.developers.google.com/. I used Android apps for Application restrictions:

对于Restrict usage to your Android apps部分,我必须提供Package nameSHA-1 certificate fingerprint. Package name在我的app/build.gradle中,具体在这里:

For the Restrict usage to your Android apps section, I had to provide a Package name and a SHA-1 certificate fingerprint. The Package name was in my app/build.gradle, specifically here:

applicationId "[my package name]"

我通过运行signingReport在Android Studio中找到了SHA-1 certificate fingerprint:

The SHA-1 certificate fingerprint I found it from Android Studio by running signingReport:

结果包括以下内容:

Alias: AndroidDebugKey
MD5: [The value]
SHA1: [The value]
SHA-256: [The value]
Valid until: Wednesday, May 5, 2049
----------

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
16:31:44: Task execution finished 'signingReport'.

现在,地图可以在我的Android应用中正常工作了

Now the map works correctly in my Android app:

更新1:令我惊讶的是,这些地图只能在Android Studio仿真器上正常工作,而不能在真正的Android物理设备上正常工作.该解决方案就是我在 https://stackoverflow.com/a/56307654/4242086 上发布的内容.

UPDATE 1: To my surprise, the maps were working correctly only on the Android Studio Emulator but not on real Android physical devices. The solution was what I posted at https://stackoverflow.com/a/56307654/4242086.

这篇关于Google Maps Android API:授权失败.确保"Google Maps Android API v2"已启用.确保以下Android密钥存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆