zoukankan      html  css  js  c++  java
  • mysql利用st_distance函数查询附近的点的功能

    • 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) 是将值转化为米

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

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

     

  • 相关阅读:
    .NetMVC过滤器
    Vue-cli配置
    回顾2019年到今天
    八皇后问题
    约瑟夫环问题
    斐波那契函数列
    提高学习效率的方法
    感受爱阅读笔记
    Android IO流汇总
    Android的AsyncTask
  • 原文地址:https://www.cnblogs.com/douzilovetiger/p/7755431.html
Copyright © 2011-2022 走看看