MySQL位置搜索

select 
    name,
    st_distance(
        point(113.327955,23.129717),
        point
    )*111195 as distance,
    address 
from table1 
where 
    st_distance(point(113.327955,23.129717),point)*111195 < 100
order by distance asc 
limit 100 

注意:

  1. 其中point字段类型是 point,其值可以通过以下方法写入:

update table1 set point = point(113.123232,24.1324234) ;

  1. st_distance 计算的结果单位是度,需要乘111195(地球半径6371000*PI/180)是将值转化为米 其它相关空间函数参考官方手册http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-mbr.html

 

posted @ 2020-08-25 13:38  大城小爱012  阅读(164)  评论(0)    收藏  举报