Calculating Distance
<?php
function distance2($latA, $lonA, $latB, $lonB)
{
$latA = deg2rad($latA);
$lonA = deg2rad($lonA);
$latB = deg2rad($latB);
$lonB = deg2rad($lonB);
$deltaLat = ($latA - $latB);
$deltaLon = ($lonA - $lonB);
$d = sin($deltaLat/2) * sin($deltaLat/2) +
cos($latA) * cos($latB) * sin($deltaLon/2) * sin($deltaLon/2);
$d = 2 * asin(sqrt($d));
return $d * 6371.01;
}