sql语句查询经纬度范围

指定一个经纬度,给定一个范围值(单位:千米),查出在经纬度周围这个范围内的数据。
经度:113.914619
纬度:22.50128
范围:2km
longitude为数据表经度字段
latitude为数据表纬度字段

SQL在mysql下测试通过,其他数据库可能需要修改

SQL语句如下:select * from location where sqrt(  

    (  

     ((113.914619-longitude)*PI()*12656*cos(((22.50128+latitude)/2)*PI()/180)/180)  

     *  

     ((113.914619-longitude)*PI()*12656*cos (((22.50128+latitude)/2)*PI()/180)/180)  

    )  

    +  

    (  

     ((22.50128-latitude)*PI()*12656/180)  

     *  

     ((22.50128-latitude)*PI()*12656/180)  

    )  

)<2  

posted @ 2014-07-19 13:03  飘逸的程序员  阅读(943)  评论(0编辑  收藏  举报