2013-01-21 32 views
5

我有被描绘在谷歌地球和包含不同的多个航线的KML文件。现在我正在尝试使用Maps API V2在我的Android项目中显示这些内容。导入KML的地图API V2

有没有在你的Android项目导入KML文件,并在地图上显示它们现有的库? 我发现堆栈溢出(How to draw a path on a map using kml file?)这不是一个库的一些代码。

如果没有可用的,我只是要从头开始构建这个库。

+0

标志多远沿着这你是谁?你在制作什么样的应用程序? – danny117

+0

查看@ http://devaarapp.nl/。德网站是荷兰语,在线演示是iOS版本,但android应用程序几乎相同。 –

回答

0

现在生病只是假设,那里有,这是否对我们所以我打算使用谷歌的代码在我的KML文件解析后的数据线与多边形添加到我的地图没有公共图书馆。 如果找到库,将更新此答案。

创建折线和多边形:

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

这是我上面推荐的第二部分。使用简单KML或其他库来分析您的KML。 – Matthew

+0

好的。 我用PHP解析了我的KML。这个脚本回声包含所有格和经度的二维数组。 该应用程序只需要创建多段线。 感谢您的所有信息 –

+0

还有用于解析KML的PHP​​库 - 您正在使用的是什么?没有必要这样做'手动' – Matthew

0

KML库的问题Maps API第2部分只是一个更新。现在有一个可用的测试版Google Maps KML Importing Utility

这是Google Maps Android API Utility Library的一部分。作为记录它允许从流加载的KML文件

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

或本地资源

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

你已经创建了一个KmlLayer后,调用addLayerToMap()将导入的数据添加到地图上。

layer.addLayerToMap(); 
+0

任何想法设置点击监听器? –