将GeoJSON属性添加到android映射中的每个标记

时间:2016-09-03 14:05:02

标签: android google-maps maps geojson markers

我使用的geojson文件有很多这样的功能:

{
"type": "FeatureCollection",
"features": [
    {
        "type": "Feature",
        "properties": {
            "Number": "233",
            "Name": "233_SAN_JUAN_BOSCO_SANTIAGO_RUSIÑOL",
            "Address": "San Juan Bosco - Santiago Rusiñol"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [
                -0.369528093405798,
                39.497128187401
            ]
        }
    },
    {
        "type": "Feature",
        "properties": {
            "Number": "211",
            "Name": "211_CALLE_FRAY_JUNÍPERO_SERRA_ESQ_CALLE_VALL_D'UIX",
            "Address": "Fray Junípero Serra - Vall d'Uixó"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [
                -0.397848157697943,
                39.45869404863428
            ]
        }
    },

因此,我将此信息添加到地图中的图层,并且所有标记都显示正确放置,但它们没有标题或摘要。我用了这段代码:

 GeoJsonLayer layer = new GeoJsonLayer(mMap, R.raw.valencia, this);

        GeoJsonPointStyle pointStyle = new GeoJsonPointStyle();

        layer.addLayerToMap();

       for (GeoJsonFeature feature : layer.getFeatures()) {  //loop through features

           pointStyle.setTitle(feature.getProperty("Number"));
           feature.setPointStyle(pointStyle);
       }

所以,正如你所看到的,我试图通过所有功能循环,为每个标记添加相应的标题(数字)。

问题在于,而不是获得单个标题,所有功能都获得相同的标题。此外,每次运行应用程序时,此标题都会更改。

知道如何修改循环以便这样做吗?

0 个答案:

没有答案