首页 > 其他分享 >位置距离经纬度计算

位置距离经纬度计算

时间:2023-03-11 15:47:24浏览次数:42  
标签:distance COS 经纬度 位置 RADIANS 距离 lat lng PI

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

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

标签:distance,COS,经纬度,位置,RADIANS,距离,lat,lng,PI
From: https://www.cnblogs.com/jingxiaoniu/p/17206162.html

相关文章