So, the ideal is to save the latitude and longitude of the places that will be saved in the bank. Then, to calculate the distance between two points there are several formulas.
This link has some formulas you can use: link
I have used the Spherical law of cosines . Here is the function I use, in php.
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}
Receiving as input the latitude and longitude of each point and a char "N" to indicate that the return is in miles or "K" to indicate that the return is in meters.
If you are working with many locations, I advise you to search for a more efficient way of storing locations so that you do not have to go through all the points in the bank. Something like, nearby cities or even nearby states.