Home > Backend Development > PHP Tutorial > php通过两个地点经纬度求距离

php通过两个地点经纬度求距离

WBOY
Release: 2016-06-23 13:44:16
Original
827 people have browsed it

/**
*求两个已知经纬度之间的距离,单位为米
*@param lng1,lng2 经度
*@param lat1,lat2 纬度
*@return float 距离,单位米
*@author yalong sun
**/
function getdistance($lng1,$lat1,$lng2,$lat2){
//将角度转为狐度
$radLat1=deg2rad($lat1);//deg2rad()函数将角度转换为弧度
$radLat2=deg2rad($lat2);
$radLng1=deg2rad($lng1);
$radLng2=deg2rad($lng2);
$a=$radLat1-$radLat2;
$b=$radLng1-$radLng2;
$s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000;
return $s;
}
echo getdistance(116.46865,39.914638,116.482233,39.91425);
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template