Adding a KML layer to an Android maps application

≡放荡痞女 提交于 2019-11-28 01:40:58

问题


I have been starting out in the world of Android development recently and I am working on an application which shows a map using the Google API SDK, it is pretty much the original example but edited a little bit. It works a treat but I wish to do more with it. My question is:

How do you add a KML layer to this? I've not found many examples out there and none of them are very clear. I know how to do this with Javascript on websites but not in android.

Can anyone help?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4096142/adding-a-kml-layer-to-an-android-maps-application

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