导入KML的地图API V2地图、KML、API

2023-09-04 11:50:01 作者:云澈

我有被画在谷歌地球,并包含不同的路线多个KML文件。现在,我试图用地图API V2显示那些在我的Andr​​oid项目。

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.

有没有导入你的Andr​​oid项目的KML文件,并在地图中显示它们现有的库? 我发现堆栈溢出一些code(How使用KML文件来绘制地图上的道路?)这不是一个图书馆。

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.

推荐答案

现在生病只是假设孤单,这是否给我们,所以我将使用谷歌的code到折线和多边形添加到任何公共图书馆我的分析数据在我的KML文件后,地图。 如果库被发现会更新这个答案。

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.

创建折线和多边形:

// 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);