Search code examples
javascriptleafletgeojson

Leaflet js, pass geoJSON to setView


I have a leaflet.js map that has a square that come from an external GeoJSON file. I want to pass the center of the square (I calculated the coordinates ) to the setView function, how do I convert the coordinates? (When I passed the values from the the GeoJSON directly to setView It showed some other place, as I understand it doesn't use the same coordinate reference system)


Solution

  • I suspect you just passed coordinates with the wrong order:

    • In GeoJSON, coordinates are [longitude, latitude]
    • In Leaflet, they are expected as [latitude, longitude]