Android:从谷歌地图获取无效的 KML 文件
我正在尝试使用以下命令从maps.google.com获取并显示实时.kml文件
Uri.parse("geo:0,0?q=http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=104538451667315338387.0004887d133ba2ab6eec9&ll=42.029611,-93.646109&spn=0.011396,0.022724&z=16l&output=kml");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapUri);
startActivity(Intent.createChooser(mapIntent, "lol"));
但是,在打开地图视图后,我收到一条通知,显示“社区地图无法显示,因为它包含错误”,
只有在以下情况下我才会收到此错误直接从maps.google 下载.kml。如果我将完全相同的链接复制到地址栏中,下载 .kml 文件,然后将其上传到其他地方,那么它就可以正常工作。我希望能够直接从 Google 获取地图,这样我就可以进行更改,并且它会立即反映给我的用户。
I'm trying to get and display a live .kml file from maps.google.com using
Uri.parse("geo:0,0?q=http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=104538451667315338387.0004887d133ba2ab6eec9&ll=42.029611,-93.646109&spn=0.011396,0.022724&z=16l&output=kml");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapUri);
startActivity(Intent.createChooser(mapIntent, "lol"));
However after opening the mapview I get a notification saying "The community map could not be displayed because it contains errors"
I only get this error if I download the .kml directly from maps.google. If I copy the exact same link into my address bar, download the .kml file, and upload it elsewhere then it works fine. I would like to be able to get the maps directly from Google that way I can make a change and it would be immediately reflected to my users.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题 - 如果你使用“&”作为参数分隔符,Android 版 Google 地图会截断 URL,因此请使用“%26”:
I had the same problem - if you use "&" as parameter separator, Google Maps for Android cuts off the URL, so use "%26" instead:
尝试在某处将 Android 下载的数据显示为文本(即通过 System.out.println),也许它包含 google 错误消息描述
try to display Android-downloaded data as text somewhere (i.e. thru System.out.println), maybe it contains google error message description
我不久前解决了这个问题,并认为我会为面临此问题的其他人进行更新。我使用的解决方案是将链接复制到自定义地图,附加 &output=kml ,并使用链接缩短服务。由于某种原因,android 只是不喜欢谷歌地图提供的 URL,并且文件本身绝对没有问题。
这远非一个优雅的解决方案,因为我依赖 Google 地图和我选择的 URL 缩短器来将 KML 文件发送到用户的手机。如果其中任何一个失败,那么我的系统将无法工作。
我对其他选择持开放态度,如果出现其他选择,我会更改我的答案。
I solved this a while ago and figured I would update for anyone else facing this problem. The solution I used was copying the link to the custom map, appending &output=kml , and using a link shortening service. For some reason android just does not like the URL that google maps gives, and it has absolutely no problem with the file itself.
This is far from an elegant solution, as I am relying on both Google Maps and My URL shortener of choice to work to get the KML file to the user's phone. If either of them fails then my system won't work.
I am open to other options and will change my answer if another arises.
如果您仅使用普通的maps.google.com 链接创建意图,而不使用“&output=kml”怎么办?
What if you create the intent with just the plain maps.google.com link, without the "&output=kml"?