使用OsmBonusPack解析和查看GeoJSON

3
2个回答

5

以下是我的步骤,用一个给定的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();

}

2

是的,您可以使用此方法:KmlDocument.parseGeoJSON(File file)。还有一些变体,例如:KmlDocument.parseGeoJSON(String jsonString)。

如果想进一步了解,请下载并查看javadoc文档。


谢谢@MKer,我会尝试。 - gokhangokce

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接