Leaflet中的GeoJSON错误无效 - Android

时间:2013-10-14 09:27:00

标签: android leaflet geojson

我在Android中使用Leaflet ..我想在Leaflet中使用GeoJSON ..

宣传单官方网站saying,我可以无缝使用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"
}

当我从herehere检查后,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时,没有错误。

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

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]
    }
};

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

1 个答案:

答案 0 :(得分:1)

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