【问题标题】:Import KML in Maps API V2在 Maps API V2 中导入 KML
【发布时间】:2013-01-04 17:20:10
【问题描述】:

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

是否存在用于在您的 android 项目中导入 KML 文件并在地图中显示它们的库? 我发现了一些关于堆栈溢出的代码(How to draw a path on a map using kml file?),这不是一个库。

如果没有可用的库,我会从头开始构建它。

【问题讨论】:

  • 马克,你在这方面走了多远?你在做什么样的应用?
  • 查看@devaarapp.nl。 de 网站是荷兰语,在线演示是 iOS 版本,但 android 应用程序几乎相同。

标签: java android google-maps overlay kml


【解决方案1】:

现在我只假设没有公共库可以为我们执行此操作,因此我将在解析我的 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);

【讨论】:

  • 这是我上面推荐的第二部分。使用 Simple KML 或其他库来解析您的 KML。
  • 好的。我用 PHP 解析了我的 KML。此脚本回显包含所有纬度和经度的二维数组。该应用程序只需要创建折线。感谢您提供所有信息
  • 还有用于解析 KML 的 PHP 库 - 您正在使用这些库吗?无需“手动”执行此操作
  • 不需要库。只需几行代码即可完成此操作。只是想知道是否有库结合了解析和在地图上显示。
  • 对点击监听器或事件有什么想法吗?
【解决方案2】:

只是对 Maps API V2 部分问题的 KML 库 的更新。现在有 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();

【讨论】:

  • 有什么想法可以设置点击监听器吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-28
  • 2020-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-11
相关资源
最近更新 更多