问题
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