我想解析GeoJSON并在osmbonuspack和osmdroid地图视图上查看数据。我使用了这个教程:
https://code.google.com/p/osmbonuspack/wiki/Tutorial_4
有没有像解析KML一样解析GeoJSON文件的方法?
谢谢。
https://code.google.com/p/osmbonuspack/wiki/Tutorial_4
有没有像解析KML一样解析GeoJSON文件的方法?
谢谢。
以下是我的步骤,用一个给定的GeoJSON
文件和问题中提供的链接创建了一个新的覆盖层。
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();
}
是的,您可以使用此方法:KmlDocument.parseGeoJSON(File file)。还有一些变体,例如:KmlDocument.parseGeoJSON(String jsonString)。
如果想进一步了解,请下载并查看javadoc文档。