mysql 計算兩座標間的距離

mysql 5.6.1 加入了空間數據支持功能,新增了st_*相關函數,能夠很是方便的計算兩個地理座標點的距離了。html

以下例子:按個人座標計算周邊座標的距離並由近到遠排序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 100sql

注意:其中point字段類型是 point,其值能夠經過如下方法寫入:app

update table1 set point = point(113.123232,24.1324234)函數

st_distance 計算的結果單位是 度,須要乘111195(地球半徑6371000*PI/180) 是將值轉化爲米spa

#獲取文本值htm

select astext(shape), name from waypoints blog

 

其它相關空間函數參考官方手冊排序

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

參考

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

st_distance函數參考

相關文章
相關標籤/搜索