MongoDB/Mongoose:使用 geoJSON 使用 geoNear 方法获取不正确的距离

MongoDB/Mongoose:Getting incorrect distance with geoNear method using geoJSON

我已将我的架构定义为

var locationSchema = new mongoose.Schema({
  coords: {
    type: [Number],
    index: '2dsphere'
  },
});

geoJSON 对象定义为

var geoOptions = {
    spherical: true,
    maxDistance: 5000,
    distanceMultiplier : 0.001,
    num: 10
}
loc.geoNear(point, geoOptions, function(error, results, stats){//do stuff});

loc 是我的模型实例,我的观点是

var point = {
    type: "Point",
    coordinates: [lng,lat]
};

我的数据库中有两个文档的坐标

"coords" : [
    18.9164127,
    72.8245292
]

"coords" : [
    18.935197,
    72.8249342
]

我得到这两者之间的距离为 0.619 公里,而它应该超过 2 公里。 无法弄清楚我在哪里做错了。任何帮助,将不胜感激。 提前致谢

好像没问题,你插入的坐标格式是[经度,纬度]吗?该顺序很重要,并且是 mongo 使用 geoNear 执行查询所使用的顺序。