Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if marker coordinates are in bounds

I'm using leaflet map in Angular 6 application. I get location info for each item as

[lat: xx, lng: xx]

I also get the bounds object which describes what area of map is currently visible. It changes with dragging and zooming. The bounds object looks like this:

_northEast
    lat: 76.16399261609192
    lng: 111.00585937500001
_southWest
    lat: 18.646245142670608
    lng: -43.76953125

I know I could just compare each item lat whether it's bigger than southWest.lat and smaller than northEast.lat and same with lng, but is there any easier and more elegant way to fit it in the bounds?

And yes, I looked through the leaflet docs before asking this :)

like image 694
raouaoul Avatar asked Oct 28 '25 14:10

raouaoul


1 Answers

You need LatLngBounds.contains(LatLng)

https://leafletjs.com/reference.html#latlngbounds-contains

like image 195
peeebeee Avatar answered Oct 30 '25 05:10

peeebeee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!