Import KML into Maps API V2

I have several KML files that are drawn in Google Earth and contain different routes. Now I am trying to display them in my Android project using the Maps API V2.

Is there an existing library to import KML files into your Android project and display them on maps? I found code for ( How to draw a path on a map using the kml file? ), Which is not a library.

If there is no library available, I'm just going to build it from scratch.

+5
source share
2 answers

At the moment, I just assume that there is no public library that does this for us, so I'm going to use the Google code to add polylines and polygons to my map after parsing the data in my KML file. This answer will be updated if the 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 color to red
rectOptions.color(Color.RED);

// Get back the mutable Polyline
Polyline polyline = myMap.addPolyline(rectOptions);
0
source

Just an update in the KML library for the Maps API V2 part of the API. Google Maps KML Importing Utility Beta Now Available .

This is part of the Google API Android API Utility Library . As documented, it allows you to load KML files from streams

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

or local resources

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

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

layer.addLayerToMap();
0

All Articles