<?PHP/** * @desc calculates distance according to latitude and longitude between two points * @param float $lat latitude value * @param float $lng Longitude value*/ functionGetdistance ($lat 1,$LNG 1,$lat 2,$LNG 2) { $earthRadius= 6367000;//approximate radius of earth in meters /*Convert These degrees to radians to work with the formula*/ $lat 1= ($lat 1*Pi())/180; $LNG 1= ($LNG 1*Pi())/180; $lat 2= ($lat 2*Pi())/180; $LNG 2= ($LNG 2*Pi())/180; /*Using the Haversine Formula Http://en.wikipedia.org/wiki/Haversine_formula calculate the Dist ance*/ $calcLongitude=$LNG 2-$LNG 1; $calcLatitude=$lat 2-$lat 1; $stepOne=POW(Sin($calcLatitude/2), 2) +Cos($lat 1) *Cos($lat 2) *POW(Sin($calcLongitude/2), 2);$stepTwo= 2 *ASIN(min(1,sqrt($stepOne))); $calculatedDistance=$earthRadius*$stepTwo; return round($calculatedDistance); } $lat 1= ' 36.8274190000 '; $LNG 1= ' 118.0484210000 '; $lat 2= ' 36.8419400000 '; $LNG 2= ' 118.0494970000 '; EchoGetdistance ($lat 1,$LNG 1,$lat 2,$LNG 2);
Calculates the straight distance based on the latitude and longitude of two points