0

我正在使用 Android 中的 Leaflet。我想将 GeoJSON 与 Leaflet 一起使用。

Leaflet官网我可以无缝使用FeatureCollection

依赖于此,我尝试在 Leaflet 中使用 GeoJSON,但出现错误..

我的错误是“未捕获的错误:无效的 GeoJSON 对象。在 file:///android_asset/www/leaflet.js:8”

这是我的 GeoJSON

{
    "features": [
        {
            "geometry": {
                "coordinates": [
                    [
                        [
                            32.54132554492192,
                            38.23922491639042
                        ],
                        [
                            32.54681870898355,
                            38.161522193191885
                        ],
                        [
                            32.75967881640627,
                            38.16476146212179
                        ],
                        [
                            32.68826768359334,
                            38.24030353694492
                        ],
                        [
                            32.54132554492192,
                            38.23922491639042
                        ]
                    ]
                ],
                "type": "Polygon"
            },
            "properties": {
                "name": "shapeId",
                "value": "1"
            },
            "type": "Feature"
        },
        {
            "geometry": {
                "coordinates": [
                    [
                        [
                            32.21585557421817,
                            38.209017044734495
                        ],
                        [
                            32.19937608203057,
                            38.11723776214526
                        ],
                        [
                            32.37927720507808,
                            38.123720089271345
                        ],
                        [
                            32.32571885546793,
                            38.232752857036594
                        ],
                        [
                            32.21585557421817,
                            38.209017044734495
                        ]
                    ]
                ],
                "type": "Polygon"
            },
            "properties": {
                "name": "shapeId",
                "value": "2"
            },
            "type": "Feature"
        },
        {
            "geometry": {
                "coordinates": [
                    [
                        [
                            32.55505845507735,
                            38.11507685855403
                        ],
                        [
                            32.37103745898429,
                            38.07616966143842
                        ],
                        [
                            32.3943834062496,
                            37.97015072378485
                        ],
                        [
                            32.677281355468274,
                            37.99721094465765
                        ],
                        [
                            32.55505845507735,
                            38.11507685855403
                        ]
                    ]
                ],
                "type": "Polygon"
            },
            "properties": {
                "name": "shapeId",
                "value": "3"
            },
            "type": "Feature"
        },
        {
            "geometry": {
                "coordinates": [
                    32.28452012499983,
                    37.872651327798025
                ],
                "type": "Point"
            },
            "properties": {
                "name": "shapeId",
                "value": "234"
            },
            "type": "Feature"
        },
        {
            "geometry": {
                "coordinates": [
                    32.25980088671844,
                    37.77719365533954
                ],
                "type": "Point"
            },
            "properties": {
                "name": "shapeId",
                "value": "235"
            },
            "type": "Feature"
        }
    ],
    "type": "FeatureCollection"
}

当我从这里这里检查时,JSON 没有问题..

在 Android 端,我正在使用这个命令

 mAppView.loadUrl("javascript:send('"+tmp+"')"); //tmp is my string which is converted from json

在 JavaScript 方面

function send(geojsonFeature)
{
alert(geojsonFeature);

L.geoJson(geojsonFeature).addTo(map);

}

我的错误是“未捕获的错误:无效的 GeoJSON 对象。在 file:///android_asset/www/leaflet.js:8”

它是 leaflet.js

当我尝试仅添加 Feature 而不是 FeatureCollection 时,没有错误。

例如,如果我像这样设置没有 FeatureCollection 的 tmp,则不会出现错误

tmp = {
    "type": "Feature",
    "properties": {
        "name": "Coors Field",
        "amenity": "Baseball Stadium",
        "popupContent": "This is where the Rockies play!"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-104.99404, 39.75621]
    }
};

感谢您阅读..有什么建议吗?

4

1 回答 1

1

你试着从javascript函数中删除单引号:)

于 2013-10-16T09:51:06.043 回答