Google Maps Android API示例密钥不起作用?

时间:2017-11-13 04:57:38

标签: android google-maps android-fragments

我是一个Android / Java noob试图让我的Macbook上的Google Maps Android API示例与仿真器(Nexus 5X API 26)和Android Studio一起使用。

我复制了样本的github repo并将其加载到Android Studio中。现在,项目编译,我在模拟器上有应用程序,但地图似乎没有加载在片段中。

  • 我在控制台中没有看到任何错误。
  • 我创建了我的无限制GMaps API密钥,并在清单文件和资源/调试google_maps_api.xml文件中对其进行了更新。

这是有问题的活动 https://github.com/googlemaps/android-samples/blob/master/ApiDemos/app/src/main/java/com/example/mapdemo/BasicMapDemoActivity.java

我还在onMapReady()上设置了一个断点,它确实被击中了。但片段是空白的。我该如何进一步调试?

2 个答案:

答案 0 :(得分:0)

转到android manifest(示例项目)找到这一行。

 <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

在值文件夹中,您会发现google_maps_api.xml会使用您的开发Google地图密钥更改google_maps_key的值,因为在google_maps_api.xml中明确提到了

Once you have your key (it starts with "AIza"), replace the "google_maps_key"
    string in this file.

    Note: This resource is used for the debug build target. Update this file if you just want to run
    the demo app.

如果您尚未在Google开发者控制台https://developers.google.com/ad-exchange/rtb/open-bidder/google-app-guide中创建任何项目,请检查此链接

I think there is problem with your emulator because it is working in my AVD

答案 1 :(得分:0)

I resolved it myself by switching from an emulator to a real phone.

Looks like some emulators don't come pre-loaded with Google Play services APK. That might have been the issue.