利用mongodb内置的方法查询坐标之间的距离


//    geoNear : 要查询的表名
//    near :坐标
//    num: 返回的行数
//    spherical:true   计算距离
//    distanceMultiplier: 地球半径
//    maxDistance: 最大范围
//    var near = [113.525298,22.246466];
    
yourmodle.collection.geoNear(near,{num:10, spherical:true,distanceMultiplier: 6378137,maxDistance:100/6378137}, function(err, result){
        if(err){
            console.log(err);
        } else {
            console.log(result);
        }
    });



利用mongodb内置的方法查询坐标之间的距离!

具体可看: http://docs.mongodb.org/manual/reference/command/geoNear/#dbcmd.geoNear

其中还有一个query字体可用,用于按条件查询,但不知道如何按某一字段进行排序,知道的请留言。谢谢!

db.runCommand({"geoNear":"coach2", "near":[113.525298,22.246466],"num":10, spherical:true,distanceMultiplier: 6378137,maxDistance:100/6378137, query:{account:"tcrct"}})

猜你喜欢

转载自tcrct.iteye.com/blog/2165177