Jai*_*oya 5 google-maps google-maps-api-3 google-play-services google-maps-android-api-2 google-maps-android-api-1
我收到此错误:
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>):
Run Code Online (Sandbox Code Playgroud)
这就是我所看到的,而不是地图正常工作:
在我的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'
Run Code Online (Sandbox Code Playgroud)
play-services-location
是我需要的谷歌地图,对吗?我正在查看https://developers.google.com/android/guides/setup上的列表,我认为这Google Location and Activity Recognition - com.google.android.gms:play-services-location:16.0.0
就是 Google 地图所需要的。这样对吗?
更新 1:我已经启用了 Android 版 Maps SDK:
错误说:Ensure that the "Google Maps Android API v2" is enabled.
。它是指Maps SDK for Android
我在此更新 1的屏幕截图中显示的内容吗?
更新 2:我已Maps SDK for Android
启用:
当我单击该MANAGE
按钮时,我可以转到配置我在UPDATE 1 中显示的凭据的部分。
更新 3:我看到地图在模拟器上的所有 Android 版本上都正确显示。但是在物理设备上,地图永远不会出现。我看到了 Google 徽标和红色气球,但现在我在物理手机上运行该应用程序时会看到地图。只有在模拟器上一切正常。任何想法为什么?
更新 4:在/sf/answers/3941535811/ 上查看我的解决方案。
我按照本教程进行操作并能够修复它:https://www.youtube.com/watch?v=sJBlQv6IptQ。该视频引用了本教程:http://ramsandroid4all.blogspot.com/2016/01/google-maps-android-example-in-android.html。
就我而言,我所做的是在https://console.developers.google.com/创建一个新项目。我Android apps
用于Application restrictions
:
对于该Restrict usage to your Android apps
部分,我必须提供 aPackage name
和 a SHA-1 certificate fingerprint
。是Package name
在我的app/build.gradle
,特别是在这里:
applicationId "[my package name]"
Run Code Online (Sandbox Code Playgroud)
我通过运行以下命令SHA-1 certificate fingerprint
从 Android Studio 找到了它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'.
Run Code Online (Sandbox Code Playgroud)
现在地图在我的 Android 应用程序中可以正常工作:
更新 1:令我惊讶的是,这些地图只能在 Android Studio 模拟器上正常工作,而不能在真正的 Android 物理设备上正常工作。解决方案是我在/sf/answers/3941535811/上发布的内容。