在 Android 上的 Google 地图中打开本地 KML 文件

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

Open local KML File in Google Maps on Android

androidgoogle-mapskml

提问by ahsteele

I have loaded a KML file onto an Android device. What's the easiest mechanism for loading an overlay of that KML file into Google Maps? I do not want to upload the KML file to the web but would rather open it locally.

我已将 KML 文件加载到 Android 设备上。将该 KML 文件的叠加层加载到 Google 地图中的最简单机制是什么?我不想将 KML 文件上传到网络,而是想在本地打开它。

回答by gb96

To load kml into Google Maps on Android without writing an app, you can create a little html file somewhere with a geo-uri link to the kml file and then click on that link in any Android web browser.

要在不编写应用程序的情况下将kml 加载到 Android 上的 Google 地图中,您可以在某处创建一个带有指向 kml 文件的 geo-uri 链接的小 html 文件,然后在任何 Android 网络浏览器中单击该链接。

For example: suppose your kml file is located in /sdcard/overlay.kmlthen you write a geo-uri link like this:

例如:假设您的 kml 文件位于/sdcard/overlay.kml 中,那么您编写一个 geo-uri 链接,如下所示:

<html>
<head><title>Example KML link page using a geo-uri</title></head>
<body>
  <a href="geo:0,0?q=file:///sdcard/overlay.kml">overlay.kml</a>
</body>
</html>

Clicking on the link will launch Maps and then Maps will attempt to load and your kml.

单击该链接将启动 Maps,然后 Maps 将尝试加载您的 kml。

(Obviously if your kml file is on a web server the file:// part can be replaced with http:// servername)

(显然,如果您的 kml 文件位于 Web 服务器上,则 file:// 部分可以替换为 http:// 服务器名)

Be warned however that the Android version of Maps does not appear to handle the same version/range of kml elements as the desktop version (or desktop Google Earth).

但是请注意,Android 版地图似乎无法处理与桌面版(或桌面版 Google 地球)相同的 kml 元素版本/范围。

回答by Jpsy

I cannot tell about older Android versions, but on Nexus 4 with Android 4.2.2 this is very easy:

我不能说旧的 Android 版本,但在带有 Android 4.2.2 的 Nexus 4 上这很容易:

  • Transfer the KML file to your Android device and store it on your SD card by any means (USB, eMail, PAW app,...)
  • Use some file manager app (e.g. Solid Explorer, Astro, ...) to locate the file in the file system and click it.
  • Google Earth will pop up and the KML file will be displayed on top of the Earth satellite image.
  • 将 KML 文件传输到您的 Android 设备并通过任何方式(USB、电子邮件、PAW 应用程序等)将其存储在您的 SD 卡上
  • 使用一些文件管理器应用程序(例如Solid ExplorerAstro等)在文件系统中找到该文件并单击它。
  • Google Earth 将弹出,KML 文件将显示在地球卫星图像的顶部。

In Earth you can also tap on any KML objects to display associated information (if any is stored in the KML file).

在地球中,您还可以点击任何 KML 对象以显示相关信息(如果 KML 文件中存储了任何信息)。

回答by MKer

Assuming you are OK to show your KML on OpenStreetMap instead of Google Maps, you can also use osmdroid + OSMBonusPack (https://github.com/MKergall/osmbonuspack).

假设您可以在 OpenStreetMap 而不是 Google Maps 上显示您的 KML,您还可以使用 osmdroid + OSMBonusPack ( https://github.com/MKergall/osmbonuspack)。

Depending on what you want to do:

取决于你想做什么:

  • You can just use the demo application "OSMNavigator" to load and display your KML file on the map (KML can be local or from a url).

  • Or you can use OSMBonusPack library in your application to display your KML content as you want.

  • 您只需使用演示应用程序“OSMNavigator”即可在地图上加载和显示您的 KML 文件(KML 可以是本地的或来自 url)。

  • 或者您可以在您的应用程序中使用 OSMBonusPack 库来根据需要显示您的 KML 内容。

回答by Mike Brian Olivera

File KML = new File("/sdcard/doc.kml");
Intent i = getPackageManager().getLaunchIntentForPackage("com.google.earth");
i.setDataAndType(Uri.fromFile(KML), "xml");
startActivity(i);

source: http://enladodelbien.blogspot.com/2015/06/kmlkmz-to-google-earth.html

来源:http: //enladodelbien.blogspot.com/2015/06/kmlkmz-to-google-earth.html