4

我有一个使用谷歌地图的安卓应用程序。我已按照说明使用调试键使应用程序在调试模式下工作。我已从此处找到的 debug.keystore 检索到我的 SHA-1 密钥。

c:\Users\myself\.android\debug.keystore

使用

c:\Program Files\Java\jdk1.7.0_03\bin>keytool -list -v -keystore c:\debug.keystore

每当我通过在我的测试手机(运行 android 2.3.6)上运行 eclipse 中的应用程序使用系留调试时,地图显示良好。

但是,完成应用程序后,在已发布的应用程序中,地图没有显示。看得见的只有灰色的瓷砖。

我知道这是 API 密钥的问题。

所以我创建了一个新密钥,(以及一个带有它的 apk)用它从谷歌的控制台生成一个新的 API 密钥。我删除了使用密钥生成的 apk,因为它有旧的 ApiKey,并在此处粘贴了新的 api 密钥。

<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:id="@+id/mymap"
android:apiKey="my_api_key"

然后我重新导出了我的项目,但这次使用了与我之前创建的步骤相同的密钥,因为它们包含相同的 SHA-1。

但是,地图仍然没有显示,只出现灰色瓷砖。我通过以下方式在 api 控制台中输入了我的 SHA-1 密钥。

18:3E:1D:8C:xx:xx:xx:xx:xx:xx:xx:xx:xx:x:xx:1D:E1:08:32:8E;com.mycompany.mapapp

我试图恢复到我的调试密钥,但是这次调试应用程序(从 Eclipse 运行)也没有显示任何映射。

我的问题如下。

  1. 这仍然是正确的使用方法吗?因为在 -- https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key -- 谷歌使用了不同的片段方法。

  2. 我错过了什么?

  3. 这种方法是否已弃用或应该有效?

4

2 回答 2

8

You're generating an ApiKey for the Google Maps V2, but you are using the v1 MapView com.google.android.maps.MapView. On the Android Maps V2 API, the key is placed on the manifest, and you use com.google.android.gms.maps.MapView to show the map, using the Google Play Services Library.

I suggest reading the overview section here to learn how to setup your Project with the Google Play Services Library, and looking at the new API Reference here.

于 2013-02-23T14:16:36.130 回答
5

如果你正在开发谷歌地图 api。您需要有两组地图 api 密钥。使用调试密钥库中的 SHA1 指纹生成的一个映射 api 密钥,当您在 eclipse 中调试应用程序并从那里运行它时,将使用此映射 api 密钥。另一个地图 api 密钥是使用来自官方或生产密钥库的 SHA1 指纹生成的,此地图 api 密钥在您签署或发布应用程序时使用。

我认为您在那里遇到了密钥不匹配的问题,因为清单上的 map api 密钥来自调试密钥库,并且您已经使用官方密钥库签署了您的应用程序。

另外我认为您正在开发 MapView。现在建议现在使用 MapFragments。我这里有可能对你有帮助的链接。

快速入门指南: https ://docs.google.com/document/d/1dFzZT0C782BxLkDIUEb711rmsbMmYPURFV_2Cdb36so/edit?usp=sharing

如果您遇到 MapFragment 或 Google Play 服务库问题的故障排除线程: 无法实例化 android.gms.maps.MapFragment

此外,我在此How to/Error in declaring google-play-services-component中也有答案,可能会对您有所帮助。

于 2013-02-23T13:54:44.613 回答