Algorithm to calculate nearest location based on longitude & latitude

user557419 picture user557419 · Aug 19, 2011 · Viewed 21.4k times · Source

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.

Answer

hsz picture hsz · Aug 19, 2011

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