Calculates the spherical distance between 2 points on the Earth's surface
/** * @param $lat 1 * @param $lng 1 * @param $lat 2 * @param $lng 2 * @return int*/functionGetdistance ($lat 1,$LNG 1,$lat 2,$LNG 2){ //turn angle into Fox degree $radLat 1=Deg2rad($lat 1);//the Deg2rad () function converts an angle to radians $radLat 2=Deg2rad($lat 2); $radLng 1=Deg2rad($LNG 1); $radLng 2=Deg2rad($LNG 2); $a=$radLat 1-$radLat 2; $b=$radLng 1-$radLng 2; $s=2*ASIN(sqrt(POW(Sin($a/2), 2) +Cos($radLat 1)*Cos($radLat 2)*POW(Sin($b/2), 2)) *6378.137; return $s;}/** * @param $lat 1 * @param $lon 1 * @param $lat 2 * @param $lon 2 * @param float $radius Planet radius * @return Float*/functionDistance$lat 1,$lon 1,$lat 2,$lon 2,$radius= 6378.137){ $rad=Floatval(m_pi/180.0); $lat 1=Floatval($lat 1) *$rad; $lon 1=Floatval($lon 1) *$rad; $lat 2=Floatval($lat 2) *$rad; $lon 2=Floatval($lon 2) *$rad; $theta=$lon 2-$lon 1; $dist=ACOs(Sin($lat 1) *Sin($lat 2) +Cos($lat 1) *Cos($lat 2) *Cos($theta) ); if($dist< 0 ) { $dist+=M_pi; } return $dist=$dist*$radius;}$lat 1= ' 31.253411 ';$lon 1= ' 121.518998 ';$lat 2= ' 31.277117 ';$lon 2= ' 120.744587 ';EchoGetdistance ($lat 1,$lon 1,$lat 2,$lon 2);//73.734589823361EchoDistance$lat 1,$lon 1,$lat 2,$lon 2);//73.734589823354
PHP calculates the distance between 2 points in 2 ways based on latitude and longitude.