在java中将米[X,Y]转换为[纬度,经度] for Google Map

时间:2019-12-30 06:16:47

标签: java json google-maps geojson

我的Json文件大小为177MB
我使用JsonParser迭代此文件。现在我想将[X,Y]的坐标转换为[Lat,Long]
我想将此更新后的坐标写入另一个新的geojson文件中,以显示在Google地图上

这是解析json的代码:-

public static void main(String[] args) throws Exception {
    JsonFactory f = new MappingJsonFactory();
    JsonParser jp = f.createJsonParser(new File("filename.json"));
    JsonToken current;
    current = jp.nextToken();
    if (current != JsonToken.START_OBJECT) {
        return;
    }
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jp.getCurrentName();
        current = jp.nextToken();
        if (fieldName.equals("features") || fieldName.equals("type")) {
            if (current == JsonToken.START_ARRAY) {
                while (jp.nextToken() != JsonToken.END_ARRAY) {
                    JsonNode node = jp.readValueAsTree();
                    // And now we have random access to everything in the object
                    System.out.println("field1: " + node.get("geometry"));

                    // here I want to convert and create another updated file of [Lat, Long]

                }
            } else if (current == JsonToken.VALUE_STRING) {
                System.out.println("field1: " + jp.readValueAs(String.class));
            } else {
                jp.skipChildren();
            }
        } else {
            System.out.println("Unprocessed property: " + fieldName);
            jp.skipChildren();
        }
    }
    System.out.println("Main Completed");
}

这是我在json文件中获取的数据示例

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            [
              [
                360590,
                555610
              ],
              [
                360590,
                555555.0128
              ],
              [
                360590,
                555540
              ],
              [
                360592.4439,
                555540
              ],
              [
                360600,
                555540
              ],
              [
                360600,
                555518.8277
              ]
            ]
          ]
        ]
      }
    }
  ]
}

那我要如何读取坐标值,因为我要在单个对象中获取所有数据,以及如何将其转换为[Lat,Long]

0 个答案:

没有答案