mysql 计算两坐标间的距离

mysql 5.6.1 加入了空间数据支持功能,新增了st_*相关函数,可以非常方便的计算两个地理坐标点的距离了。

如下例子:按我的坐标计算周边坐标的距离并由近到远排序

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

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

update table1 set point = point(113.123232,24.1324234)

st_distance 计算的结果单位是 度,需要乘111195(地球半径6371000*PI/180) 是将值转化为米

#获取文本值

select astext(shape), name from waypoints

 

其它相关空间函数参考官方手册

http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-mbr.html

参考

https://www.percona.com/blog/2013/10/21/using-the-new-spatial-functions-in-mysql-5-6-for-geo-enabled-applications/

st_distance函数参考

 

转载于:https://my.oschina.net/swingcoder/blog/599905

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值