Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse and view geojson with OsmBonusPack

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

like image 592
gokhangokce Avatar asked Dec 14 '25 06:12

gokhangokce


1 Answers

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

}
like image 83
shshnk Avatar answered Dec 16 '25 21:12

shshnk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!