PHP/Math/deg2rad — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:06, 26 мая 2010
float deg2rad ( float num ) converts degrees to radians.
$sin1 = sin(deg2rad(80));
Return the distance between two locations in either kilometers or miles
<?php
define("KM", 6364.963);
define("MILES", 3955.00465);
function GetDistance($la1, $lo1, $la2, $lo2, $r = KM) {
$l1 = deg2rad($la1);
$l2 = deg2rad($la2);
$dg = deg2rad($lo2 - $lo1);
$d = $r * acos(sin($l1) * sin($l2) + cos($l1) * cos($l2) * cos($dg));
return $d;
}
$lat1 = 55;
$long1 = 12;
$lat2 = 34;
$long2 = -118;
echo "The distance from Copenhagen to Los Angeles is " . round(GetDistance($lat1, $long1, $lat2, $long2)) . " km\n";
echo "The distance from Copenhagen to Los Angeles is " . round(GetDistance($lat1, $long1, $lat2, $long2, MILES)) . " miles\n";
?>