Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用GMAPSAPI将KML文件导入Android应用程序_Java_Android_Maps_Kml - Fatal编程技术网

Java 如何使用GMAPSAPI将KML文件导入Android应用程序

Java 如何使用GMAPSAPI将KML文件导入Android应用程序,java,android,maps,kml,Java,Android,Maps,Kml,我有一个使用谷歌地图API的简单应用程序,我有一个带有1000个标记的KML文件,我想在我的应用程序的地图中显示它 如何在地图中导入KML文件 我使用安卓工作室 @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION

我有一个使用谷歌地图API的简单应用程序,我有一个带有1000个标记的KML文件,我想在我的应用程序的地图中显示它

如何在地图中导入KML文件

我使用安卓工作室

@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);


}

您需要渲染贴图并在其上添加KML层。例如:

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

有关完整示例,请参阅github示例项目。如果要从本地资源加载KML数据集,如下所示:

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

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

KmlLayer layer = new KmlLayer(getMap(), kmlInputStream, getApplicationContext());
layer.addLayerToMap();
更多详情请参阅