【问题标题】:Ensure that the "Google Maps Android API v2" is enabled. Even if already enabled确保启用了“Google Maps Android API v2”。即使已经启用
【发布时间】:2018-11-15 09:36:01
【问题描述】:

我正在开发一个包含 Google Maps API 的 Android 应用程序。为此,我从 console developers 启用了这个 API

Maps SDK for Android

我创建了一个凭据,我为 App Android 设置了一个限制,我还添加了应用程序包和指纹,并且在 API 限制选项卡上,我选择了 Maps SDK for Android。 之后,在我的应用程序清单中,我为谷歌地图编写了密钥。当我从 Android Studio 构建应用程序时,一切都很好(我的手机,一加 6,插在电脑上)。地图按我的意愿工作。但是,如果我尝试安装生成的 APK(来自构建的签名 APK -> 生成签名包/APK),则地图不会显示,并且我在 logcat 上收到错误

2018-11-15 10:19:45.590 13249-13249/? I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
2018-11-15 10:19:45.590 13249-13249/? I/DynamiteModule: Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
2018-11-15 10:19:45.652 13249-13249/? I/Google Maps Android API: Google Play services client version: 12451000
2018-11-15 10:19:45.655 13249-13249/? I/Google Maps Android API: Google Play services package version: 14367037
2018-11-15 10:19:45.985 633-13359/? I/netd: ;; res_nquery(maps.googleapis.com, 1, 1)
2018-11-15 10:19:46.162 13249-13358/? W/System.err: com.google.maps.errors.RequestDeniedException: This IP, site or mobile application is not authorized to use this API key. Request received from IP address *********, with empty referer
2018-11-15 10:19:46.162 13249-13358/? W/System.err:     at com.google.maps.DirectionsApi$Response.getError(DirectionsApi.java:90)
2018-11-15 10:19:46.162 13249-13358/? W/System.err:     at com.google.maps.internal.OkHttpPendingResult.parseResponse(OkHttpPendingResult.java:289)
2018-11-15 10:19:46.162 13249-13358/? W/System.err:     at com.google.maps.internal.OkHttpPendingResult.onResponse(OkHttpPendingResult.java:207)
2018-11-15 10:19:46.250 13249-13356/? 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.
2018-11-15 10:19:46.251 13249-13356/? 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 (<cert_fingerprint>;<package_name>): *********;************

我可以在这里看到 2 个问题:

This IP, site or mobile application is not authorized to use this API

Ensure that the "Google Maps Android API v2" is enabled

我真的不明白。其实,我想不通。我启用了一切,但仍然无法正常工作。还有其他事情要做吗?

【问题讨论】:

    标签: java android api google-maps


    【解决方案1】:

    它不起作用,因为您没有在 Google Api 控制台上添加应用程序密钥库的 SHA。您可以在 Android Studio 的终端中使用以下命令获取密钥库的 SHA:-

    keytool -list -v -keystore {keystore_name} -alias {alias_name}
    

    注意:两个名称都应包含文件的完整路径,如果路径包含空格,请在引号中添加路径。

    例子:

    keytool -list -v -keystore "C:\Users\MG\Desktop\My Projects\test.jks" -alias test
    

    【讨论】:

      【解决方案2】:

      API 密钥:YOUR_KEY_HERE

      您的 API 密钥未在 android 项目中设置! 所以首先确保它存在于 AndroidManifest.xml 配置文件中。 这是我的例子

      <application>
      ....
        <meta-data
                  android:name="com.google.android.geo.API_KEY"
                  android:value="My API key" />
      </application>
      

      【讨论】:

      • OP 可能已将其用作占位符,以便在帖子中没有他们的实际密钥
      猜你喜欢
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多