eclipse 谷歌地图 api 密钥不起作用 v2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15041200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
google maps api key not working v2
提问by tony9099
I had an android application that utilizes google maps. I have followed the instuctions and made the app working in debug mode using the debug key. I have retrieved my SHA-1 key from the debug.keystore found here.
我有一个使用谷歌地图的安卓应用程序。我已按照说明操作,并使用调试键使应用程序在调试模式下工作。我已经从这里找到的 debug.keystore 中检索了我的 SHA-1 密钥。
c:\Users\myself\.android\debug.keystore
c:\Users\myself\.android\debug.keystore
using
使用
c:\Program Files\Java\jdk1.7.0_03\bin>keytool -list -v -keystore c:\debug.keystore
c:\Program Files\Java\jdk1.7.0_03\bin>keytool -list -v -keystore c:\debug.keystore
The map was showing fine whenever I used tethered debug by running the app from eclipse on my test phone (which ran android 2.3.6).
每当我通过在我的测试手机(运行 android 2.3.6)上从 eclipse 运行应用程序来使用联机调试时,地图显示良好。
However, after finishing the app, in the published app the map did not show. What was visible were only grey tiles.
但是,完成应用程序后,在已发布的应用程序中,地图没有显示。可见的只有灰色瓷砖。
I know this is an issue with the API key.
我知道这是 API 密钥的问题。
So I created a new key, (and an apk with it) used it to generate a new API key from the google's console. I deleted the apk that was generated with the key, as it had the old ApiKey, and pasted the new api key here.
所以我创建了一个新密钥,(和一个带有它的 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"
Then I re exported my project but this time used the same key that I had created the step before as they contained the same SHA-1.
然后我重新导出了我的项目,但这次使用了与我之前创建的步骤相同的密钥,因为它们包含相同的 SHA-1。
However, still the map does not show and only grey tiles appear. I have entered my SHA-1 key in the api console in the following way.
但是,地图仍然没有显示,只显示灰色图块。我已通过以下方式在 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
18:3E:1D:8C:xx:xx:xx:xx:xx:xx:xx:xx:xx:x:xx:1D:E1:08:32:8E;com.mycompany.mapapp
I tried to revert back to my debug key, but this time the debug app (running from eclipse) also did not show any maps.
我试图恢复到我的调试密钥,但这次调试应用程序(从 eclipse 运行)也没有显示任何地图。
my questions are the following.
我的问题如下。
Is this still the correct method to use? Because in the --https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key-- google used different approach using fragments.
What am I missing ?
Is this method deprecated or should work ?
这仍然是正确的使用方法吗?因为在 -- https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key-- 谷歌使用不同的方法使用片段。
我错过了什么?
此方法是否已弃用或应该有效?
回答by Marcelo
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.
您正在为 Google Maps V2 生成 ApiKey,但您使用的是 v1 MapView com.google.android.maps.MapView
。在 Android Maps V2 API 上,密钥放置在清单上,您可以com.google.android.gms.maps.MapView
使用 Google Play 服务库来显示地图。
I suggest reading the overview section hereto learn how to setup your Project with the Google Play Services Library, and looking at the new API Reference here.
回答by Ariel Magbanua
If you are developing google maps api. You need to have two sets of map api key. One map api key that is generated by using your SHA1 fingerprint from your debugging keystore, this map api key is to be used when you are debugging your app in eclipse and running it from there. The other map api key is generated by using your SHA1 fingerprint from official or production keystore, this map api key is used when you will signed or publish your app.
如果您正在开发谷歌地图 api。您需要有两组地图 api 密钥。使用调试密钥库中的 SHA1 指纹生成的一个映射 api 密钥,当您在 eclipse 中调试应用程序并从那里运行它时,将使用此映射 api 密钥。另一个地图 API 密钥是通过使用来自官方或生产密钥库的 SHA1 指纹生成的,当您签署或发布您的应用程序时将使用此地图 API 密钥。
I think you are experiencing mismatch of your keys there since the map api key on the manifest is from debugging keystore and you have signed your app with your official keystore.
我认为您在那里遇到了密钥不匹配的问题,因为清单上的映射 api 密钥来自调试密钥库,并且您已经使用官方密钥库对您的应用程序进行了签名。
Also I think you are developing MapView. It is recommended now to use MapFragments now. I have links here that might help you.
另外我认为您正在开发 MapView。现在建议现在使用 MapFragments。我这里有可能对你有帮助的链接。
Quick Start Guide: https://docs.google.com/document/d/1dFzZT0C782BxLkDIUEb711rmsbMmYPURFV_2Cdb36so/edit?usp=sharing
快速入门指南:https: //docs.google.com/document/d/1dFzZT0C782BxLkDIUEb711rmsbMmYPURFV_2Cdb36so/edit?usp=sharing
Trouble shooting thread if you encounter problems with MapFragment or Google Play Services Library: Unable instantiate android.gms.maps.MapFragment
遇到 MapFragment 或 Google Play 服务库问题时的故障排除线程: 无法实例化 android.gms.maps.MapFragment
Also I have answers here in this How to/Error in declaring google-play-services-componentthat might help you.
此外,我在此How to/Error in declaring google-play-services-component 中提供了可能对您有所帮助的答案。