如何在maxDistance为1km的情况下查询geoNear的模型?
这是我的猫鼬模式 -
var userDestinationSchema = mongoose.Schema({
uid: String,
update_time: Date,
location:{ //<INDEXED as 2d>
lon: Number,
lat: Number
}
});
var userDestinationModel = mongoose.model('userDestinationModel', userDestinationSchema);
我尝试过这样做而且无法正常工作。
userDestinationModel.geoNear([parseInt(req.params.lon,10),parseInt(req.params.lat,10)],
{ maxDistance : 1, spherical : true },
function(err, results, stats) {
console.log(results);
});
但当我删除 spherical : true
时,它可以正常工作。
maxDistance的单位是多少?在传统坐标的情况下, //答案: Radian 。
DataSample:
{ _id: ObjectId("52f89d8cdbe6f9ea80344fd9"), location: { lon: 165, lat: 165 }, uid: "testuser2", update_time: ISODate("2014-02-10T09:36:12.705Z") }
{ _id: ObjectId("52f89d97dbe6f9ea80344fda"), location: { lon: 166, lat: 166 }, uid: "testuser3", update_time: ISODate("2014-02-10T09:36:23.236Z") }
{ _id: ObjectId("52f8a16edbe6f9ea80344fdb"), location: { lon: 164, lat: 164 }, uid: "testuser4", update_time: ISODate("2014-02-10T09:52:46.464Z") }
{ _id: ObjectId("52f8a173dbe6f9ea80344fdc"), location: { lon: 164, lat: 164 }, uid: "testuser1", update_time: ISODate("2014-02-10T09:52:51.125Z") }
{ _id: ObjectId("52f8a17fdbe6f9ea80344fdd"), location: { lon: 165, lat: 165 }, uid: "testuser7", update_time: ISODate("2014-02-10T09:53:03.365Z") }
答案 0 :(得分:2)
单位为米,因此您可能无法得到正确答案。
对于km,请指定50*1000
也许你需要根据这个来编辑你的查询文件:
http://docs.mongodb.org/manual/reference/command/geoNear/
{ near: POINT_COORDINATES.....