20

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.

ahsteele
  • 26,243
  • 28
  • 134
  • 248
  • think this is a duplicate, but of a previously unresolved question. http://stackoverflow.com/questions/2444639/does-the-android-api-support-kml-files – Adam May 28 '10 at 19:33
  • @Adam didn't see that one even after some extensive searching. The low view number and the lack of an answer there has me worried. – ahsteele May 28 '10 at 21:41
  • you can access that in your MapView by Intent and then it prompts you to open that file either into default Maps or in Web Site. – Harshad Apr 01 '11 at 09:55

4 Answers4

14

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

gb96
  • 1,674
  • 1
  • 18
  • 26
  • @Rodrigo yes, currently only on Android devices AFAIK. Further details on the geo: URI scheme available at or . Sample page containing geo: links to kml: – gb96 Jan 11 '12 at 06:47
  • 1
    Dropbox links no longer working. Try pastebin instead: http://pastebin.com/raw.php?i=6DxNmx4x – gb96 Jul 17 '13 at 06:21
  • 4
    Not working for me, just opens gmaps searching for "file:///sdcard/overlay.kml" and finding no results – RASMiranda Aug 08 '14 at 12:09
2

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

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

Jpsy
  • 20,077
  • 7
  • 118
  • 115
1

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.

Paweł Szczur
  • 5,484
  • 3
  • 29
  • 32
MKer
  • 3,430
  • 1
  • 13
  • 18
1
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

Mike Brian Olivera
  • 1,414
  • 1
  • 16
  • 21
  • This doesn't seem to work any more. According to https://support.google.com/earth/thread/87413940 : "There's currently no API for Google Earth. You might be able to do something with the Google Maps API - https://developers.google.com/maps/documentation . The support options are at the bottom of that page." – Henrik R. Dec 09 '20 at 14:45
  • OBS! In any case you need to use a file provider - content URI - nowadays. But that didn't solve it for me. – Henrik R. Dec 09 '20 at 17:50