eee also:
http://blog.csdn.net/lynnlovemin/article/details/51880261
http://www.cnblogs.com/zflinux21/archive/2012/02/07/2341428.html
+++++++++++++++++++++++++++++++++++++++++
sql 语句查询经纬度范围
+++++++++++++++++++++++++++++++++++++++++
`create table x (name varchar(32), x decimal(9,6), y decimal(9,6));
INSERT INTO x (name,x,y ) VALUES ('地点 1', 39.895496,116.347996 );
INSERT INTO x (name,x,y ) VALUES ('中心点', 39.876739 , 116.396574 ) ;
INSERT INTO x (name,x,y ) VALUES ('地点 2', 39.884790 , 116.389644 ) ;
`
查询离“中心点”2 公里范围内的坐标。
SELECT
name,x,y,
round(6378.1382asin(sqrt(pow(sin( (39.876739pi()/180-xpi()/180)/2),2) + cos(39.876739pi()/180)cos(xpi()/180) pow(sin( (116.396574 * pi()/180- y * pi()/180)/2),2)))*1000) distance
FROM x
WHERE
( y between 116.396574 - 10 / 111.12 and 116.396574 + 10 / 111.12 ) -- 先缩小查询范围
and ( x between 39.876739 - 10 / 111.12 and 39.876739 + 10 / 111.12 ) -- 先缩小查询范围
++++++++++++++++++++++++++++++++++++++
mongodb 查询地理位置
++++++++++++++++++++++++++++++++++++++
db.x.save({ "point":"广安门桥" , "xy": [ 116.347996 , 39.895496 ] } )
db.x.save({ "point":"中海地产" , "xy": [ 116.396574 , 39.876739 ] })
db.x.save({ "point":"陶然亭地铁" , "xy": [ 116.389644 , 39.884790 ] })
db.x.ensureIndex({"xy":"2d"},{"min":-180,"max":180})
1)标准查询, 为地球经纬度查询内置;
参数一为查询条件利用 $near 查找附近,
参数二 $maxDistance 为经纬弧度(1° latitude = 111.12 kilometers)即 1/111.12,表示查找附近一公里。
db.x.find({ "xy" :{ near : [ 116.396574 , 39.876739 ] , maxDistance : 1 /111.12} })
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于