0
votes

i am working with Leaflet in Android.. I want to use GeoJSON with Leaflet..

Leaflet official website is saying that i can use FeatureCollection seamlessly

Relying on this, i tried to use GeoJSON in Leaflet but i am getting an error..

My error is "Uncaught Error: Invalid GeoJSON object. at file:///android_asset/www/leaflet.js:8"

Here My 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"
}

When I've checked from here and here, there is no problem about JSON..

At the Android side, i am using this command

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

At the JavaScript side

function send(geojsonFeature)
{
alert(geojsonFeature);

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

}

My error is "Uncaught Error: Invalid GeoJSON object. at file:///android_asset/www/leaflet.js:8"

and it is leaflet.js

When i try to add just Feature instead of FeatureCollection, there is no error.

For example, if i set tmp without FeatureCollection like this, error not appearing.

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

Thank you for reading.. Any suggestions ?

1

1 Answers

1
votes

you try just delete single quotes from javascript function :)