Adding a KML layer to an Android maps application

匆匆过客 提交于 2019-11-29 08:13:06

Google added a support to KML recently in its utility lib. You can instantiate a KMLLayer as below:

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

Or if you have a stream (maybe the kml you need is on a remote server):

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

After this you have to add the layer to the map:

layer.addLayerToMap();

More info on Google Maps KML Importing Utility. The library is here: Google Maps Android API utility library (you need 0.4+ version)

CAUTION: At the time, it's a Beta feature. In fact it seems you can't make any modifications to polygons, changing their styles, and so on...

I hope it helped.

If you are ready to move to OpenSteetMap maps, then you can use osmdroid and OSMBonusPack to have KML support for: reading, saving, displaying and styling.

There is a dedicated tutorial about KML.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!