#查询偏差经纬度1度(111公里)范围内,按距离排序,获得最近的前10个
#输入
#lat = 22
#lang = 113
select * from location where lat > 22-1 and lat < 22+1 and lang > 113-1 and lang < 113+1
order by ACOS(SIN((22 * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((22 * 3.1415) / 180 )
* COS((lat * 3.1415) / 180 ) * COS((113* 3.1415) / 180 - (lang * 3.1415) / 180 ) ) * 6380 asc limit 10;
#查询偏差经纬度1度(111公里)范围内,按距离排序,获得最近的前10个
select * from location where lat > '.$lat.'-1 and lat < '.$lat.'+1 and lang > '.$lon.'-1 and lang < '.$lon.'+1
order by ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 )
* COS((lat * 3.1415) / 180 ) * COS(('.$lon.'* 3.1415) / 180 - (lang * 3.1415) / 180 ) ) * 6380 asc limit 10;
#输入
#lat = 22
#lang = 113
# 查询2km范围内
select 6371.012 * acos(cos(acos(-1) / 180 * d.lat) * cos(acos(-1) / 180 * 22) *
cos(acos(-1) / 180 * d.lang - acos(-1) / 180 * 113) +
sin(acos(-1) / 180 * d.lat) *
sin(acos(-1) / 180 * 22))*1 as a,
id, lat, lang
from location d
where 6371.012 *
acos(cos(acos(-1) / 180 * d.lat) *
cos(acos(-1) / 180 * 22) *
cos(acos(-1) / 180 * d.lang - acos(-1) / 180 * 113) +
sin(acos(-1) / 180 * d.lat) *
sin(acos(-1) / 180 * 22))*1 < 2 order by a asc;