我有多个 KML 文件,它们是在谷歌地球中绘制的,并且包含不同的路线。现在我正在尝试使用 Maps API V2 在我的 android 项目中显示这些内容。
是否有一个现有的库可以在您的 Android 项目中导入 KML 文件并在地图中显示它们?
我在堆栈溢出上找到了一些代码(如何使用kml文件在地图上绘制路径?)这不是图书馆。
如果没有可用的库,我将从头开始构建它。
现在,我假设没有公共库可以为我们执行此操作,因此在解析 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)