I have a function in PHP
which calculates the distance between two places.
Here is the php code :
function distance($lat1, $lon1, $lat2, $lon2) {
$earth_radius = 6371;
$delta_lat = $lat2 - $lat1 ;
$delta_lon = $lon2 - $lon1 ;
$distance = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($delta_lon)) ;
$distance = acos($distance);
$distance = rad2deg($distance);
$distance = $distance * 60 * 1.1515;
$distance = round($distance, 4);
return $distance = $distance * 1.609344;
}
It gives good calculations around 25 km
, but around 500 km
the calculations are wrong.
My other question is it really giving miles or kilometers?
For example this map gives a distance of 443 km
from Morbi
to Surat
, but the function gives me a result of 274 km