Android-osmdroid-kml
osmdroid 加载kml/kmz文件
首先增加导入
compile 'com.github.MKergall:osmbonuspack:6.5.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
32class KmlLoader extends AsyncTask<Void, Void, Void> {
ProgressDialog progressDialog = new ProgressDialog(context);
KmlDocument kmlDocument;
protected void onPreExecute() {
super.onPreExecute();
progressDialog.setMessage("Loading Project...");
progressDialog.show();
}
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;
}
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);
}
}引用代码
new KmlLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);