I want to use this formula with php. I have a database with some values of latitute and longitude saved.
I want to find, with a certain value of latitude and longit
from this link:
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371;
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;
return $d;
}
As you can see there are many differences between this as your code. I don't know if you have either a different approach to the formula or maybe some step when converting to PHP went wrong, but the above formula should work.