Nearest Layer in Leaflet

57 views
Skip to first unread message

New Leaflet User

unread,
Nov 7, 2016, 7:49:08 AM11/7/16
to Leaflet
I have 2 Layers (Customers & Suppliers), I want to get the nearest suppliers to a specific customers,can anyone help me in that with example?

Thanks in advance.

k_man_au

unread,
Nov 7, 2016, 9:12:15 PM11/7/16
to Leaflet
You need to use the Havesine formula to calc distance between Customers and Suppliers. To make sure you're not running too big of a loop, use a bounding box to narrow your results before you run through and check distances. 

Malcolm Meyer

unread,
Nov 8, 2016, 9:15:38 AM11/8/16
to Leaflet
Take a look at the turf js library. It will do what you are looking for, though you may have to tweak their examples. There is an example here - you will have to adjust abut for using leaflet instead of mapbox. - https://www.mapbox.com/help/analysis-with-turf/
Reply all
Reply to author
Forward
0 new messages