5

I have multiple KML files which are drawn in google earth and contain different routes. Now I'm trying to display those in my android project with Maps API V2.

Is there an existing library for importing KML files in your android project and displaying them in maps? I found some code on stack overflow ( How to draw a path on a map using kml file? ) which isn't a library.

If there's no library available I'm just going to build this from scratch.

Community
  • 1
  • 1
Mark Molina
  • 5,057
  • 8
  • 41
  • 69
  • Mark,How far along on this are you? What kind of app are you making? – danny117 Aug 26 '13 at 23:33
  • check it out @ http://devaarapp.nl/. De website is in dutch and the online demo is the iOS version but the android app is practically the same. – Mark Molina Aug 28 '13 at 10:48

2 Answers2

0

For now Ill just assume that theres no public library that does this for us so I'm going to use Google's code to add polylines and polygons to my map after parsing the data in my KML file. Will update this answer if a library is found.

Create Polylines and Polygons:

// Instantiates a new Polyline object and adds points to define a rectangle
PolylineOptions rectOptions = new PolylineOptions()
        .add(new LatLng(37.35, -122.0))
        .add(new LatLng(37.45, -122.0))  // North of the previous point, but at the same longitude
        .add(new LatLng(37.45, -122.2))  // Same latitude, and 30km to the west
        .add(new LatLng(37.35, -122.2))  // Same longitude, and 16km to the south
        .add(new LatLng(37.35, -122.0)); // Closes the polyline.

// Set the rectangle's color to red
rectOptions.color(Color.RED);

// Get back the mutable Polyline
Polyline polyline = myMap.addPolyline(rectOptions);
Mark Molina
  • 5,057
  • 8
  • 41
  • 69
  • This is the second part of what I am recommending above. Use the Simple KML or other library to parse your KML. – Matthew Jan 22 '13 at 15:38
  • Ok. I parsed my KML with PHP. This script echos a two dimensional array containing all the latt & longitudes. The app only needs to create polylines. Thanks for all the info – Mark Molina Jan 22 '13 at 17:11
  • There are also PHP libraries for parsing KML - is that what you are using? There is no need to do this 'manually' – Matthew Jan 22 '13 at 17:29
  • No library needed. Done this in a few lines of code. Just wanted to know if there were libraries that combined the parsing and showing on the map. – Mark Molina Jan 23 '13 at 12:07
  • any idea for click listener or event? – Andrew Indayang Jul 15 '16 at 02:13
0

Just an update on the KML library for Maps API V2 part of the question. There is now a beta available of Google Maps KML Importing Utility.

It is part of the Google Maps Android API Utility Library. As documented it allows loading KML files from streams

KmlLayer layer = new KmlLayer(getMap(), kmlInputStream, getApplicationContext());

or local resources

KmlLayer layer = new KmlLayer(getMap(), R.raw.kmlFile, getApplicationContext());

After you have created a KmlLayer, call addLayerToMap() to add the imported data onto the map.

layer.addLayerToMap();
ben-efiz
  • 813
  • 9
  • 13