19
Working on a bike share map script. Hitting a wall with data sorting.
Teaching myself JavaScript for fun. Trying to plot local bike stations on a map to show green travel options. My array of locations won't sort by distance from user input. How do you compare coordinates in code?
3 comments
Log in to join the discussion
Log In3 Comments
carr.brooke1mo ago
I used to try and sort raw lat/lng numbers myself, which was a mess. The Haversine formula for the actual distance (you know, the math for earth curves) made it click for me. Plugging that into the sort function got my map working.
7
mia_sullivan1mo ago
Wait how did you actually plug it into the sort function
2
logan7051mo ago
Verify your Haversine function uses radians for the trig parts. Degrees will mess up the distances. I once plotted stations in the wrong country by missing that step. Are you using kilometers or miles for the earth's radius? That can shuffle your sorted list. It's the kind of bug that makes you stare at the screen for an hour.
7