Leaflet.js and geojson with wrong order of latitude and longitude

🗄️ Code
Leaflet and geojson might sometimes have issues because of a standards confusion. This is how to fix it

You might end up with geojson that has latitude and longitude in different order than what leaflet.js expects. If that is the case, here is what you need:

L.geoJSON(json, {
    coordsToLatLng: function(coords) {
        return new L.LatLng(coords[0], coords[1], coords[2]);
    }
}).addTo(mymap);

Voila!


Subscribe to my newsletter where I send new links from all my blogs and curated links related to society, politics, etc.

Or find other ways to follow me