Parse and view geojson with OsmBonusPack

无人久伴 提交于 2020-01-24 14:09:06

问题


I want to parse geojson and view data on osmbonuspack & osmdroid mapview. I used this totorial:

https://code.google.com/p/osmbonuspack/wiki/Tutorial_4

IS there any way to parse a geojson file like kml?

thanks


回答1:


Here is how I created a new overlay using a given GeoJSON file and the link given in question.

private void addAdditionalLayer () {
    String jsonString = null;
    try {
        InputStream jsonStream = getAssets().open("myLocations.geojson");
        int size = jsonStream.available();
        byte[] buffer = new byte[size];
        jsonStream.read(buffer);
        jsonStream.close();
        jsonString = new String(buffer,"UTF-8");
    } catch (IOException ex) {
        ex.printStackTrace();
        return;
    }

    KmlDocument kmlDocument = new KmlDocument();
    kmlDocument.parseGeoJSON(jsonString);
    FolderOverlay myOverLay = (FolderOverlay)kmlDocument.mKmlRoot.buildOverlay(mapView,null,null,kmlDocument);
    mapView.getOverlays().add(myOverLay );
    mapView.invalidate();

}



回答2:


Yes: you have this method: KmlDocument.parseGeoJSON(File file) And some variants like: KmlDocument.parseGeoJSON(String jsonString)

To go further than tutorials, download and look at the javadoc.



来源:https://stackoverflow.com/questions/26790500/parse-and-view-geojson-with-osmbonuspack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!