Search code examples
androidgeojsonosmdroid

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


Solution

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