I have a list of points with latitude and longitude coordinates, from which I want to enter a point say X. I need help coming up with an algorithm to determine the closest 3 list members to that point x.
Asked
Active
Viewed 557 times
1
-
http://stackoverflow.com/questions/7120872/algorithm-to-calculate-nearest-location-based-on-longitude-latitude – Joe Jun 28 '12 at 14:28
2 Answers
1
You'll probably have to use the Haversine Formula. It calculates Great Circle distance between two points on the Earth's surface. Here's a good article explaining that, and here's an answer to a question similar to yours. Hope that helps!
0
See the method computeDistanceBetween() in the google.maps.geometry.spherical namespace:
https://developers.google.com/maps/documentation/javascript/reference#spherical
Then, here's an old V2 demo that uses Array.sort():
http://maps.forum.nu/gm_array_sort.html
You could combine the two, implementing computeDistanceBetween() instead of compareDistance() as the sorting function. Note that this is all done client side.

Marcelo
- 9,387
- 3
- 35
- 40