从字符串显示geojson

时间:2018-10-10 12:46:23

标签: android maps geojson

在我的应用中,我从API接收数据。我的对象的一部分是可以显示为geojson的几何。字符串看起来像这样:

 {"type": "Polygon", "coordinates": [[[22.22, 22.22], [22.22, 22.22], [22.22,22.22 ], ... , ]]}

请问如何将其转换为geojson(多边形)并以最简单的方式显示在地图上?

2 个答案:

答案 0 :(得分:0)

您可以使用这种 POJO类来进行解析:

package com.foo;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Foo {

    @SerializedName("type")
    @Expose
    private String type;

    @SerializedName("coordinates")
    @Expose
    private List<List<List<Double>>> coordinates = null;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<List<List<Double>>> getCoordinates() {
        return coordinates;
    }

    public void setCoordinates(List<List<List<Double>>> coordinates) {
        this.coordinates = coordinates;
    }

}

现在,使用此类在地图上显示您的路线。

答案 1 :(得分:0)

您的json如下

{
"type": "Polygon",
"coordinates": [
    [22.22, 22.22],
    [22.22, 22.22],
    [22.22, 22.22]
]

}

您可以使用this链接将任何类型的json转换为pojo类。

相关问题