如何用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") }发布于 2014-02-10 11:37:13
单位是米,所以你可能没有得到正确的答案。对于km,指定50*1000
也许您需要根据以下内容编辑查询文档:
http://docs.mongodb.org/manual/reference/command/geoNear/
{ near: POINT_COORDINATES.....
https://stackoverflow.com/questions/21675166
复制相似问题