时间:2021-07-01 10:21:17 帮助过:4人阅读
select ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($latitude*PI()/180-latitude*PI()/180)/2),2)+COS($latitude*PI()/180)*COS(latitude*PI()/180)*POW(SIN(($longitude*PI()/180-longitude*PI()/180)/2),2)))*1000) AS distance FROM shop having distance <= 5000 order by distance asc
php:
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 floor($s); }
文章摘自:https://www.cnblogs.com/wrld/p/9377680.html
PHP,Mysql根据经纬度计算距离并排序
标签:mysq ret adl turn func dash das 单位 经纬