用 $geoWithin returns 空数组订阅
Subscribing with $geoWithin returns empty array
每次我尝试 return 集合中的一些数据时,它 return 都是一个空数组。我正在使用铁路由器,这是我的代码:
客户:
Meteor.call('insertEvent', {
"eventLoc": {
"type" : "Point",
"coordinates": [
eventLongitude,
eventLatitude
]}
}
function getBox() {
var bounds = GoogleMaps.maps.mapSeek.instance.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]);
}
getbox();
服务器:
Meteor.publish('publicPlaces', function(box) {
var find = {
eventLoc: {
$geoWithin: {
$box: box
}
}
};
return Events.find(find);
});
路线:
Router.route('/seek', function () {
this.render('seek');
Meteor.subscribe('publicPlaces', Session.get('box'));
};
我认为,错误在于您的 box
值。根据 MongoDB 手册,您必须先指定经度,而代码 Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]);
似乎正好相反。
每次我尝试 return 集合中的一些数据时,它 return 都是一个空数组。我正在使用铁路由器,这是我的代码:
客户:
Meteor.call('insertEvent', {
"eventLoc": {
"type" : "Point",
"coordinates": [
eventLongitude,
eventLatitude
]}
}
function getBox() {
var bounds = GoogleMaps.maps.mapSeek.instance.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]);
}
getbox();
服务器:
Meteor.publish('publicPlaces', function(box) {
var find = {
eventLoc: {
$geoWithin: {
$box: box
}
}
};
return Events.find(find);
});
路线:
Router.route('/seek', function () {
this.render('seek');
Meteor.subscribe('publicPlaces', Session.get('box'));
};
我认为,错误在于您的 box
值。根据 MongoDB 手册,您必须先指定经度,而代码 Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]);
似乎正好相反。