在Maps API V2中导入KML

Mar*_*ina 5 java android google-maps overlay kml

我有多个KML文件,这些文件在谷歌地球上绘制并包含不同的路线.现在,我正在尝试使用Maps API V2在我的android项目中显示这些内容.

是否有一个现有的库,用于在Android项目中导入KML文件并在地图中显示它们?我在堆栈溢出上找到了一些代码(如何使用kml文件在地图上绘制路径?),这不是库.

如果没有可用的库,我只是从头开始构建它.

Mar*_*ina 0

现在,我假设没有公共库可以为我们执行此操作,因此在解析 KML 文件中的数据后,我将使用 Google 的代码将折线和多边形添加到我的地图中。如果找到库,将更新此答案。

创建折线和多边形:

// 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);
Run Code Online (Sandbox Code Playgroud)