我正在尝试将适用于 Android 的 Maps API v2 添加到正在 Android Studio 中构建的项目中。我通过 build.gradle 文件和 maven 添加 Google Play 服务(它是通过 SDK 管理器中的 Google 存储库导入的)。我将以下内容添加到项目内的 build.gradle 文件中:
compile "com.google.android.gms:play-services:3.1.36"
这几乎完美地工作。我能够在代码中使用 API 并在 XML 中引用它们。例如,我正在使用 LocationClient 来检索用户位置;我可以将 com.google.android.gms.MapView 添加到 XML 文件中,它可以完美构建和运行。
问题是 map 无法显示。现在,我已将以下内容添加到我的 list 中:
<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"/>
<application ...>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="[MY API KEY HERE]"/>
</application>
我通过使用调试证书获得了API key ;我已在 API 控制台中打开“Google Maps Android API v2”。一切似乎都设置得很好,但 map 仍然无法加载。有什么帮助吗?
最佳答案
在此处检查文档:
Users of this class must forward all the Activity life cycle methods - such as onCreate(), onDestroy(), onResume(), and onPause() - to the corresponding methods in the MapView class.
如果您忽略此步骤,您将遇到 map 无法加载的问题。
关于android - Android Maps API v2、Gradle 和 Android Studio 不会显示 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18025113/