Home > php教程 > php手册 > 贴一段根据坐标计算距离的代码,有LBS开发的可以借鉴

贴一段根据坐标计算距离的代码,有LBS开发的可以借鉴

WBOY
Release: 2016-06-07 11:41:00
Original
1521 people have browsed it

根据坐标计算出距离,精确小数点后两位
function rad($d)
{
return $d * M_PI / 180.0;
}
/**
* 获取两个坐标点之间的距离,单位km,小数点后2位
*/
function GetDistance($lat1, $lng1, $lat2, $lng2)
{
$EARTH_RADIUS = 6378.137;
$radLat1 = rad($lat1);
$radLat2 = rad($lat2);
$a = $radLat1 - $radLat2;
$b = rad($lng1) - rad($lng2);
$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));
$s = $s * $EARTH_RADIUS;
$s = round($s * 100) / 100;
return $s;
}

AD:真正免费,域名+虚机+企业邮箱=0元

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template