简体   繁体   中英

Open local KML File in Google Maps on Android

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.

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.

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

<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.

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

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).

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

  • 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 (eg 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.

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

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 ).

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM