【问题标题】:How to Import a KML file into Android Application with GMaps API如何使用 GMaps API 将 KML 文件导入 Android 应用程序
【发布时间】:2016-10-08 15:40:07
【问题描述】:

我有一个使用 Google Maps API 的简单应用程序,并且我有一个带有 1000 个标记的 KML 文件,我想在我的应用程序的 MAP 中显示它。

如何在我的地图中导入 KML 文件?

我使用 Android Studio

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    mMap.setMyLocationEnabled(true);


}

【问题讨论】:

    标签: java android maps kml


    【解决方案1】:

    如果要从本地资源加载 KML 数据集,如下所示:

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

    如果要从本地流中加载 KML 数据集,如下所示:

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

    更多详情请关注Maps Andriod API documentation

    【讨论】:

      【解决方案2】:

      您需要渲染地图并在其上添加一个 KML 图层。示例:

      KmlLayer kmlLayer = new KmlLayer(mMap, R.raw.coordinates, getApplicationContext());
      kmlLayer.addLayerToMap();
      

      完整示例参考thisgithub示例项目

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-22
        • 1970-01-01
        • 2018-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-16
        相关资源
        最近更新 更多