Android:从谷歌地图获取无效的 KML 文件

发布于 2024-09-04 08:32:53 字数 600 浏览 10 评论 0原文

我正在尝试使用以下命令从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

画离情绘悲伤 2024-09-11 08:32:53

我遇到了同样的问题 - 如果你使用“&”作为参数分隔符,Android 版 Google 地图会截断 URL,因此请使用“%26”:

Intent navigateToIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
    "geo:0,0?q=http://m.konzoomer.com/kml?id=" + id +
    "%26latitudeE12=" + latitudeE12 + "%26longitudeE12=" + longitudeE12 +
    "%26radiusMeters=" + radiusMeters));

I had the same problem - if you use "&" as parameter separator, Google Maps for Android cuts off the URL, so use "%26" instead:

Intent navigateToIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
    "geo:0,0?q=http://m.konzoomer.com/kml?id=" + id +
    "%26latitudeE12=" + latitudeE12 + "%26longitudeE12=" + longitudeE12 +
    "%26radiusMeters=" + radiusMeters));
等数载,海棠开 2024-09-11 08:32:53

尝试在某处将 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

掀纱窥君容 2024-09-11 08:32:53

我不久前解决了这个问题,并认为我会为面临此问题的其他人进行更新。我使用的解决方案是将链接复制到自定义地图,附加 &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.

忘羡 2024-09-11 08:32:53

如果您仅使用普通的maps.google.com 链接创建意图,而不使用“&output=kml”怎么办?

What if you create the intent with just the plain maps.google.com link, without the "&output=kml"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文