【发布时间】:2015-02-27 10:29:08
【问题描述】:
我正在使用 GeoJSON 存储我希望稍后通过邻近度查询的位置坐标,
我的架构如下所示:
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var BranchSchema = new Schema({
parentId: {
type: Schema.Types.ObjectId,
required: 'The ID of the restaurant is required.',
index: true
},
name: {
type: 'String',
required: 'The name is required.'
},
loc: {
'type': {
type: 'String',
default: 'Point'
},
coordinates: {
type: [Number],
default: [0,0]
}
}
});
BranchSchema.index({loc: "2dsphere"});
module.exports = mongoose.model('Branch', BranchSchema);
我正在使用猫鼬,我的查询如下所示:
Branch.where('loc').near({
center: [long, lat],
maxDistance: proximity,
spherical: true
}).exec(function (err, branches) {
if (err) {
return res.status(400)
.send({
message: errors.getErrorMessage(err)
});
}
return res.json(branches);
});
我在数据库中添加了一个新分支,其坐标如下纬度:34.237918 经度:36.002197 我用以下坐标查询数据库: 纬度:33.882957 经度:35.502319 最大距离为 100
这两个坐标相差超过100m但是数据库返回结果,我错过了什么???
【问题讨论】:
标签: node.js mongodb mongoose coordinates geojson