给定一个定义了包含 GeoJSON 位置的文档的模式;
var BranchSchema = new Schema({
location: {
'type': {
type: String,
required: true,
enum: ['Point', 'LineString', 'Polygon'],
default: 'Point'
},
coordinates: [Number]
},
name: String
});
BranchSchema.index({location: '2dsphere'});
以下是一些示例数据:
[
{
"name": "A",
"location": {
"type": "Point",
"coordinates": [153.027117, -27.468515 ] //Brisbane, Australia
}
},
{
"name": "B",
"location": {
"type": "Point",
"coordinates": [153.029884, -27.45643] //Also Brisbane, Australia
}
}
]
以下的geoNear查询没有按照预期运行。我的理解是,这个查询是“给定一个南美海岸附近的位置,搜索所有位置并找出距离提供的位置在1米范围内的任何位置”。
// Somewhere off the east coast of South America.
var point = {type: 'Point', coordinates: [0.0776590, -33.7797590]};
Branch.geoNear(point, {maxDistance:1, spherical: true}, function (err, data) {
...
// at this point I expected data.length === 0.
// Instead it is returning both documents.
...
});
我做错了什么?
- 按照WGS84标准,当定义位置时,我使用[经度,纬度]。
- 正在使用MongooseJS V3.8.8。