I am currently trying to develop an algorithm to calculate which known locations are closest to current known location.
I have a list of say 100 known locations (meaning I have both long- and latitude). Out of these 100 I pick one location, and after picking that location I want a list to show say the 8 closest known locations to this.
How would a possible solution be to this?
Edit
I am not looking for how to calculate distances. I am looking for how to calculate which known locations lies closest to current location.
Example:
Say the list contains 100 locations of movie theaters. I am at theater 5, and I want to find out what other movie theaters in the list lies nearby. Not the distance, but their location.
There is a Distance Matrix API. This API allows you to calculate distances between some given positions.
You can do this also by your own with a haversine formula
1st idea: If your "100 known locations" remain mostly the same, you could partition the known locations to smaller groups and maintain the structure. Then just play with the closest group.
The below link can be helpful.
http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
Try to implement k-d tree algorithm with Nearest neighbor search.
来源:https://stackoverflow.com/questions/7120872/algorithm-to-calculate-nearest-location-based-on-longitude-latitude