位置距离经纬度计算

mysql 经纬度转换距离查询

$lng //经度

$lat //纬度

方案1:

select id,address,lng,lat,round(6371*acos( COS(RADIANS($lat)) * COS(RADIANS(lat))*COS(RADIANS(lng) - RADIANS($lng)) + SIN(RADIANS($lat)) * SIN(RADIANS(lat)) ),4) as distance from table order by distance asc

方案2:

select id,address,lng,lat,round(6371*sqrt( pow((PI()*(abs(`lat`-$lat))/180) * cos(PI()*(`lat`+$lat)/360),2) + pow((PI()*abs(`lng`- $lng)/180),2)),4) as distance from table order by distance asc

以上就是今天的全部内容!

posted @ 2023-03-11 15:26  静小妞  阅读(32)  评论(0编辑  收藏  举报