question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

L.latLngBounds swapping longitude of Northeast and Southwest point

See original GitHub issue

Consider the example below

var southWest = L.latLng(-7.12725588946924, 159.14), northEast = L.latLng(70.0415297179124, 24.855900000000005);
var bounds = L.latLngBounds(southWest, northEast);

//logs - LatLng(-7.12726, 159.14), LatLng(70.04153, 24.8559)
console.log(southWest.toString(), northEast.toString());

//logs - LatLng(-7.12726, 24.8559)
console.log('bounds SW: ', bounds.getSouthWest().toString());
//logs - LatLng(70.04153, 159.14)
console.log('bounds NE: ', bounds.getNorthEast().toString());

Longitude for SouthWest and NorthEast points are swapped in the bounds. Why? This seems like a very bad bug. Issue reproduction - http://jsbin.com/huziqi/edit?html,console

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ghybscommented, Sep 16, 2016

Hi,

If I am not mistaken, the conventional cardinal directions and latitude / longitude ranges are:

             North (+90)
               |
(-180) West ———+——— East (+180)
               |
             South (-90)

Therefore your southWest = L.latLng(-7.12725588946924, 159.14) would actually be more East than your northEast = L.latLng(70.0415297179124, 24.855900000000005).

When creating your bounds out of these corners, Leaflet detects the correct positions for you. Is not it great? 😃

1reaction
ghybscommented, Sep 16, 2016

@aaani Look at your blue polygon, it crosses the dateline.

A very easy workaround would have been to use a longitude of 159.14 - 360 = -200.86 to reach the left copy of the world. Demo: https://jsfiddle.net/3v7hd2vx/80/

See https://github.com/Leaflet/Leaflet/pull/1293

Read more comments on GitHub >

github_iconTop Results From Across the Web

L.latLngBounds swapping longitude of Northeast and ... - GitHub
Longitude for SouthWest and NorthEast points are swapped in the bounds. Why? This seems like a very bad bug. Issue reproduction - http://jsbin....
Read more >
leaflet - L.latLngBounds swapping longitude of Northeast and ...
i am trying to adjust map in a certain way. logs of general bound: bottomRight: (2) [11.525595058977732, 140.82915421731286] topLeft: (2) ...
Read more >
LatLngBounds | Google Play services
Creates a new bounds based on a southwest and a northeast corner. The bounds conceptually includes all points where: the latitude is in...
Read more >
L.LatLngBounds - WRLD3D
LatLngBounds. Represents a rectangular geographical area on a map. Usage example. var southWest = L.latLng(40.712, -74.227), northEast = L.latLng(40.774, ...
Read more >
One Way to Give a National Map Geographical Detail
You'll note Alaska is an exception to this method, as it's true geographical bounds extend past the anti-meridian or 180th meridian, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found