function spherical_law_of_cosines($lat_1, $lon_1, $lat_2, $lon_2, $unit = 'mi')
{
$distance = (3956 * acos(cos(deg2rad($lat_1)) * cos(deg2rad($lat_2)) * cos(deg2rad($lon_2) - deg2rad($lon_1)) + sin(deg2rad($lat_1)) * sin(deg2rad($lat_2))));
if(strcasecmp($unit, 'mi') == 0 OR strcasecmp($unit, 'miles') == 0)
{
return $distance;
}
if(strcasecmp($unit, 'km') == 0 OR strcasecmp($unit, 'kilometres') == 0 OR strcasecmp($unit, 'kilometers') == 0)
{
return 1.609344 * $distance;
}
if(strcasecmp($unit, 'm') == 0 OR strcasecmp($unit, 'metres') == 0 OR strcasecmp($unit, 'meters') == 0
)
{
return 1.609344 * 1000 * $distance;
}
if(strcasecmp($unit, 'y') == 0 OR strcasecmp($unit, 'yards') == 0)
{
return 1760 * $distance;
}
if(strcasecmp($unit, 'ft') == 0 OR strcasecmp($unit, 'feet') == 0)
{
return 1760 * 3 * $distance;
}
return $distance;
}