PHP根据经纬度计算距离
2021/12/4 14:46:32
本文主要是介绍PHP根据经纬度计算距离,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/** * 根据经纬度算距离,返回结果单位是公里,先纬度,后经度 * @param $lat1 //地点1纬度 * @param $lng1 //地点1经度 * @param $lat2 //地点2纬度 * @param $lng2 //地点2经度 * @return float|int */ function GetDistance($lat1, $lng1, $lat2, $lng2){ $earth_radius = 6378.137;//地球半径km $radLat1 = rad($lat1); $radLat2 = rad($lat2); $a = $radLat1 - $radLat2; $radLng1 = rad($lng1); $radLng2 = rad($lng2); $b = $radLng1 - $radLng2; $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 * 10000) / 10000; return $s; } function rad($d){ return $d * M_PI / 180.0; }
这篇关于PHP根据经纬度计算距离的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-05易优新手phpStudy本地安装教程-icode9专业技术文章分享
- 2024-07-03php客户端微信小程序根据分享携带参数进入指定页面-icode9专业技术文章分享
- 2024-07-02phpstrom链接ftp 提示上传成功 但是ftp代码没变-icode9专业技术文章分享
- 2024-06-30百度空间安装易优,如何去除URL中的index.php-icode9专业技术文章分享
- 2024-06-30宝塔Linux服务器隐藏index.php-icode9专业技术文章分享
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享