Android-osmdroid-kml

osmdroid 加载kml/kmz文件

  1. 首先增加导入compile 'com.github.MKergall:osmbonuspack:6.5.2'

  2. 添加代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
        class KmlLoader extends AsyncTask<Void, Void, Void> {
    ProgressDialog progressDialog = new ProgressDialog(context);
    KmlDocument kmlDocument;

    @Override
    protected void onPreExecute() {
    super.onPreExecute();
    progressDialog.setMessage("Loading Project...");
    progressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... voids) {
    File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/osmdroid/"+Config.KMLFILENAME);
    kmlDocument = new KmlDocument();
    //加载kml文件修改为parseKMLFile
    kmlDocument.parseKMZFile(f);
    FolderOverlay kmlOverlay = (FolderOverlay)kmlDocument.mKmlRoot.buildOverlay(mapView, null, null,kmlDocument);
    mapView.getOverlays().add(kmlOverlay);
    return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
    progressDialog.dismiss();
    mapView.invalidate();
    BoundingBox bb = kmlDocument.mKmlRoot.getBoundingBox();
    mapView.zoomToBoundingBox(bb, true);
    // mapView.getController().setCenter(bb.getCenter());
    super.onPostExecute(aVoid);
    }
    }
  3. 引用代码new KmlLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

shp kml kmz文件转换可以用Google earth桌面软件

或者Tools-geoserver-base