gokhangokce
gokhangokce

Reputation: 461

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

Upvotes: 3

Views: 2523

Answers (2)

shshnk
shshnk

Reputation: 1691

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

}

Upvotes: 5

MKer
MKer

Reputation: 3450

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.

Upvotes: 2

Related Questions