Mysql当前经纬度距离排序及距离范围内数量计算

database

$lon = "XXX.XXX";//经度

$lat = "XXX.XXX";//纬度

//以以上经纬度为中心从近到远排序

SELECT ROUND(6378.138*2*ASIN(SQRT(POW(SIN(({$lat}*PI()/180-lat*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(lat*PI()/180)*POW(SIN(({$lon}*PI()/180-lon*PI()/180)/2),2)))*1000) AS juli FROM index_user WHERE lon > 0 ORDER BY juli ASC

$location_range = 100;//100米内

//以以上经纬度为中心100内用户数量

SELECT COUNT(1) AS total FROM (

SELECT ROUND(6378.138*2*ASIN(SQRT(POW(SIN(({$lat}*PI()/180-lat*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(lat*PI()/180)*POW(SIN(({$lon}*PI()/180-lon*PI()/180)/2),2)))*1000) AS juli FROM index_user WHERE lon > 0) AS a WHERE juli <= {$location_range}

 

以上是 Mysql当前经纬度距离排序及距离范围内数量计算 的全部内容, 来源链接: utcz.com/z/534359.html

回到顶部