需求:查询指定经纬度,指定范围的公交站点,例如查询经度:113.925258, 纬度:27.628368,附近5000米的公交站点
使用函数:ST_Distance_Sphere,作用查询两点间距离,单位米(直线距离),和百度地图测距数据基本一致
具体实现SQL如下
select t.*,
ST_Distance_Sphere(st_setsrid(st_makepoint(longitude,latitude),4326),
st_setsrid(st_makepoint(113.925258,27.628368),4326)) AS distance
from t_stop t
where ST_Distance_Sphere(
st_setsrid(st_makepoint(longitude,latitude),4326),
st_setsrid(st_makepoint(113.925258,27.628368),4326)) <=5000
order by distance Asc