Android“你好,MapView”教程 - 地图瓦片不加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1809507/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:39:04  来源:igfitidea点击:

Android "Hello, MapView" Tutorial - Map Tiles Do Not Load

androidgoogle-mapsandroid-mapview

提问by Onyx

I am new to Android software development and new to this site. I am hoping someone might have some experience with the problem I am having.

我是 Android 软件开发的新手,也是本网站的新手。我希望有人可能对我遇到的问题有一些经验。

I've been following the Hello, MapView tutorialin order to not only learn the Android framework, but also the Google Maps library. I've tried my best to implement things exactly as the tutorial has instructed. My problem is that the application does load in my emulator (or even on my phone for that matter), but the map tiles do not load.

我一直在关注Hello, MapView 教程,以便不仅学习 Android 框架,还学习 Google 地图库。我已尽我所能完全按照教程的指示来实现。我的问题是该应用程序确实在我的模拟器中加载(或者甚至在我的手机上),但地图图块没有加载。

Searching Google I found a post by someone else on another site having the same issue, but his/her problem was that the important elements added to the AndroidManifest.xml file were not in the right order. I double-checked this in mine, but everything seems to be right.

搜索谷歌我在另一个网站上发现了其他人的帖子有同样的问题,但他/她的问题是添加到 AndroidManifest.xml 文件的重要元素的顺序不正确。我仔细检查了我的,但一切似乎都是正确的。

So, I am not sure what the issue is and was hoping others have seen this before. I can provide any snippets of code, if that would help.

所以,我不确定问题是什么,并希望其他人以前见过这个。如果有帮助,我可以提供任何代码片段。

Thank you.

谢谢你。

回答by Jeremy Logan

Non-loading tiles are usually the result of not having the API key set up correctly. Obtaining a Maps API key

未加载磁贴通常是未正确设置 API 密钥的结果。获取 Maps API 密钥

To answer the response you left to d.: If you want to have it "just work" when you run from Eclipse you'll need to get an API key for your debug certificate. There's instructions on the same pageas before. Do note that you'll have to swap back to your other key before publishing though.

要回答您留给 d. 的响应:如果您希望在从 Eclipse 运行时让它“正常工作”,您需要为您的调试证书获取 API 密钥。与以前相同的页面上有说明。请注意,您必须在发布之前换回另一个密钥。

回答by Dan Lew

I am guessing the issue is not that you have an incorrect map key, but that you do not have the proper keystore setup. The application needs to be signed by the same keystore you used to generate the map key. You've noted that you can get it to work when you sign the application yourself, but you need to setup a debug keystore in order to use the Maps API with regular Eclipse builds.

我猜问题不是您的映射密钥不正确,而是您没有正确的密钥库设置。应用程序需要由您用来生成映射密钥的同一个密钥库签名。您已经注意到,您可以在自己对应用程序进行签名时使其工作,但是您需要设置一个调试密钥库,以便在常规 Eclipse 构建中使用 Maps API。

All Eclipse builds require a debug keystore; you just normally don't notice it because ADT generates one for you automatically. You should either follow the directions hereand create your own debug keystore, or you should take the debug key that ADT automatically created for you (it'll show you where it created it in Windows > Preferences > Android > Build) and sign up for another Maps API key. That key will work with Eclipse.

所有 Eclipse 构建都需要一个调试密钥库;您通常不会注意到它,因为 ADT 会自动为您生成一个。您应该按照此处的说明创建您自己的调试密钥库,或者您应该使用 ADT 自动为您创建的调试密钥(它会在Windows > Preferences > Android > Build 中向您显示它的创建位置)并注册另一个 Maps API 密钥。该密钥将与 Eclipse 一起使用。

(P.S., this does make it a hassle to compile for release, as you need to switch your key back and forth depending on the signing keystore.)

(PS,这确实让编译发布变得很麻烦,因为您需要根据签名密钥库来回切换您的密钥。)

回答by Alan LaMielle

I had the issue of tiles not loading as well. As you mentioned your original post, one possibility is with the ordering of elements in the AndroidManifest.xml file. Specifically, I originally had the line:

我也遇到了瓷砖未加载的问题。正如您在原始帖子中提到的,一种可能性是对 AndroidManifest.xml 文件中的元素进行排序。具体来说,我最初有这样一行:

<uses-permission android:name="android.permission.INTERNET" />

after the application element. Once I moved this line before the application element, my map tiles started loading again.

在应用程序元素之后。一旦我将这一行移动到应用程序元素之前,我的地图图块就会再次开始加载。

回答by dxh

The tiles not loading is almost always a result of using an inaccurate API-key, i think. Have you checked yours?

我认为,未加载的图块几乎总是使用不准确的 API 密钥的结果。你检查过你的吗?

Details: Obtaining a Maps API key

详细信息:获取 Maps API 密钥

回答by mario

I had the same problem... my error was in the manifest file puting INTERNETpermissions inside application. After moveing it out (upside) everying was working good.

我有同样的问题......我的错误是在清单文件中将INTERNET权限放入应用程序中。将其移出(向上)后,一切正常。

回答by 0l33l

Make sure you have 3g on the top panel. If you don't then there is no internet connection. Sometimes I have to turn the emulator on and off a couple of times to get 3g to come up.

确保顶部面板上有 3g。如果不这样做,则没有互联网连接。有时我必须打开和关闭模拟器几次才能启动 3g。

回答by Prachi

Another problem could be a proxy that you are behind. The proxy slows things down a lot and it will effect your app even though the maps app and internet browser in the emulator work fine.

另一个问题可能是您落后的代理。代理会大大减慢速度,即使模拟器中的地图应用程序和互联网浏览器工作正常,它也会影响您的应用程序。

回答by perza

This is old question, but here is one more answer: if you are as hasty as me, you might accidentally copy the finger print code instead of API key from the web page :)

这是一个老问题,但这里还有一个答案:如果你和我一样仓促,你可能会不小心从网页上复制指纹代码而不是 API 密钥:)

回答by Alex

The Hello, MapView tutorial your were talking about is no longer valid. New V1 map applications can no longer be done.

您所谈论的您好,MapView 教程不再有效。不能再做新的V1地图应用。

Follow https://developers.google.com/maps/documentation/android/for Google Maps Android API v2 applications.

按照https://developers.google.com/maps/documentation/android/获取 Google Maps Android API v2 应用程序。

回答by CommonsWare

d. is probably correct. However, Internet problems will also cause similar symptoms. Be sure that your INTERNETpermission is properly positioned and that there are no proxy servers/firewalls impeding access to the Internet.

d. 可能是正确的。但是,Internet 问题也会导致类似的症状。确保您的INTERNET权限正确定位,并且没有代理服务器/防火墙阻碍访问 Internet。