Algorithm to calculate nearest location based on longitude & latitude

萝らか妹 提交于 2019-12-04 08:35:54

问题


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.


回答1:


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




回答2:


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.

More mathematical approaches here




回答3:


The below link can be helpful.

http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL




回答4:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!