This function will calculate the distance between point A (latitude,
longitude) and point B (latitude, longitude) returning a distance in
miles.
<?php
function lat_long_dist($lat1, $long1, $lat2, $long2){
$pi = pi();
$x = sin($lat1 * $pi/180) *
sin($lat2 * $pi/180) +
cos($lat1 * $pi/180) *
cos($lat2 * $pi/180) *
cos(($long2 * $pi/180) - ($long1 * $pi/180));
$x = atan((sqrt(1 - pow($x, 2))) / $x);
return (1.852 * 60.0 * (($x/$pi) * 180)) / 1.609344;
}
echo lat_long_dist(56.34342, 49.324523, 57.49544, 47.421524);
Nessun commento:
Posta un commento