Search code examples
leafletgeojson

Invalid GeoJSON object


I am trying to draw a json coordinates in leaflet map.Here is my data

var location={
  "type": "FeatureCollection",
  "features": [
    { "type": "Feature",
      "geometry": {"coordinates": [80.2066734649931, 13.0187039189613]},
      "properties": {
          "assetStatus": "FULL",
          "id": 1747,
          "item": "53 Trailer"
      }
    },
    { "type": "Feature",
      "geometry": {"coordinates": [ 80.2072495864164, 13.0191043036246]},
      "properties": {
          "assetStatus": "EMPTY",
          "id": 1746,
          "item": "53 Trailer"
      }
    },
    { "type": "Feature",
      "geometry": { "coordinates": [ 80.2067574402883, 13.0191983952581]},
      "properties": {
          "assetStatus": "LOADED",
          "id": 1745,
          "item": "53 Trailer"
      }
    }
  ]
}


L.geoJson(location, {
            style : fillAssetColorStyle
        }).addTo(map);

Am getting Invalid GeoJSON object. error.Is my data structure correct? Anyone help me guys please.


Solution

  • Because you are missing to put geometry type. "type": "Point"

    GeoJSON supports the following geometry types:

    Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon.

    {
      "type": "FeatureCollection",
      "features": [
        { "type": "Feature",
          "geometry": {"type": "Point","coordinates": [80.2066734649931, 13.0187039189613]},
          "properties": {
              "assetStatus": "FULL",
              "id": 1747,
              "item": "53 Trailer"
          }
        },
        { "type": "Feature",
          "geometry": {"type": "Point","coordinates": [ 80.2072495864164, 13.0191043036246]},
          "properties": {
              "assetStatus": "EMPTY",
              "id": 1746,
              "item": "53 Trailer"
          }
        },
        { "type": "Feature",
          "geometry": { "type": "Point","coordinates": [ 80.2067574402883, 13.0191983952581]},
          "properties": {
              "assetStatus": "LOADED",
              "id": 1745,
              "item": "53 Trailer"
          }
        }
      ]
    }