What i want to do is develop an algorithm to calculate which known locations are closest to the selected location. Let's say i have 7 locations in the database and when the user selects one, he should have the option to see the, let's say, first 3 closest locations (from the database). In the database, each location is saved with latitude and longitude.
Any idea on how i can do that?
Example: Say the list contains 100 locations of bike stations. I am at station 5, and I want to find out what other stations in the list lies nearby. Not the distance, but their location.
Good question, Let's think we have following three value in DB:
Create a function for the distance between two places:
Define current place:
Find Records within 1KM:
You can view a great example on how to calculate it here.
From this site: