sabato 5 gennaio 2013

Calculate distance between points

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(pow($x2))) / $x);
    return (
1.852 60.0 * (($x/$pi) * 180)) / 1.609344;
}


echo 
lat_long_dist(56.3434249.32452357.4954447.421524);

Nessun commento:

Posta un commento

Friends