mapbox / cheap-ruler

Fast approximations for common geodesic measurements 🌐
https://www.mapbox.com/blog/cheap-ruler/
ISC License
417 stars 32 forks source link

along giving incorrect results #46

Closed brendan33 closed 4 years ago

brendan33 commented 4 years ago

I've implemented along into a project and noticed some strange results (returned points being either too far along the line, or not far enough). I just found this Codepen via Google and it is seems to be giving incorrect results too. The green circle should be 250m from the top blue circle, but measuring the distance on Google Maps puts it not even close, at ~208m image

image

Interestingly, ruler.distance puts the total line length at 852m, but Google Maps says it's 739m.

Am I missing something here?

PS. the codepen example is using an older version, but changing to v3.0.1, and after a few tweaks to get it running, the results are basically the same.

mourner commented 4 years ago

The issue is that Leaflet accepts coordinates in [latitude, longitude] form, while Cheap Ruler assumes [longitude, latitude]. If you swap the order, the calculation is correct.

brendan33 commented 4 years ago

Well that's embarrassing! Thanks!