【问题标题】:Subscribing with $geoWithin returns empty array使用 $geoWithin 订阅返回空数组
【发布时间】:2016-12-06 13:39:02
【问题描述】:

每次我尝试从集合中返回一些数据时,它都会返回一个空数组。我正在使用铁路由器,这是我的代码:

客户:

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'));
};

【问题讨论】:

    标签: javascript mongodb meteor meteor-blaze


    【解决方案1】:

    我认为,错误在于您的 box 值。根据 MongoDB 手册,您必须先指定经度,而代码 Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]); 似乎相反。

    【讨论】:

    • 当然,我对自己错过了这一点感到非常生气。谢谢
    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 2015-05-07
    • 2017-07-12
    • 2021-12-05
    • 1970-01-01
    • 2021-07-05
    • 2020-01-03
    • 1970-01-01
    相关资源
    最近更新 更多