1

I am trying to display some point data on a map but my GeoJSON does not appear to be able to display correctly. I have an example GeoJSON whose formatting looks somewhat different and it displays as expected. Why would my own GeoJSON data not be showing up? Does it matter if there are single quotes(') instead of double quotes(") around my GeoJSON objects? Do the line breaks in the files make a difference?

Example GeoJSON file that displays correctly:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "name": "Van Dorn Street",
        "marker-color": "#0000ff",
        "marker-symbol": "rail-metro",
        "line": "blue"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -77.12911152370515,
          38.79930767201779
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Franconia-Springfield",
        "marker-color": "#0000ff",
        "marker-symbol": "rail-metro",
        "line": "blue"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -77.16797018042666,
          38.766521892689916
        ]
      }
    }]
}

My GeoJSON file that will not show up:

{'features': [{'geometry': {'coordinates': [-122.422216, 37.803984],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.636624, 37.896388],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.289032, 37.530356],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-121.841152, 37.359752],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.787728, 38.040532],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.264464, 37.38644],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.399976, 37.324488],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.393328, 37.785076],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.236712, 37.77722],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.918952, 38.713456],
                            'type': 'Point'},
               'properties': {'event_type': 'CONSTRUCTION'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-121.940904, 37.48692],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.244136, 37.847788],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.016928, 37.702488],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-121.894048, 37.327368],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.40064, 37.623452],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.15772, 37.470228],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-121.978664, 38.354412],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-121.922752, 37.70084],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.091136, 37.897676],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'},
              {'geometry': {'coordinates': [-122.251472, 37.583248],
                            'type': 'Point'},
               'properties': {'event_type': 'INCIDENT'},
               'type': 'Feature'}],
 'type': 'FeatureCollection'}

snippet of script where I call GeoJSON file:

$.getJSON("traffic_events.geojson", function(data) {

      var geojson = L.geoJson(data, {
        onEachFeature: function (feature, layer) {
          layer.bindPopup("HELLO");
        }
      });

      geojson.addTo(map);
    });
  • 1
    Yes, in my experience, the quote character does make a difference. – Vince Oct 27 '18 at 1:14
3

If you put your GeoJSON through the GeoJSONLint validator you will see the following error:

Line 0: Parse error on line 1: ..."FeatureCollection",'features': [{'geome -----------------------^ Expecting 'STRING', got 'INVALID'

If you look at the JSON specification you will see that it states that:

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, ...

So yes the issue here is with your use of single quotes. Changing all single quotes to double and putting through the validator makes your output valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.