gpt4 book ai didi

javascript - 来自 sub geo id XXX TypeError : Cannot read property 'lng' of null 的异常

转载 作者:行者123 更新时间:2023-11-30 12:18:16 25 4
gpt4 key购买 nike

我正在使用 Mdg:geolocation 并具有以下应用程序。

查找用户的当前位置并检索距离用户一定距离内的帖子(出现错误,页面卡在加载屏幕)。 lng 为 null 表示 loc 未定义。

发布

  Meteor.publish('geo', function(loc) {     
return Posts.find({
"loc": { // error line for server.js 13:30
$near: {
$geometry: { type: "Point", coordinates: [loc.lng, loc.lat] },
.....


路由器

Router.route('/near/:postsLimit?', { 
name: 'nearPosts',
waitOn: function(){
return Meteor.subscribe('geo');
}
});


Error message

最佳答案

在你的路由中(转载如下),只有一个this.params.postsLimit,没有this.params._id

Router.route('/near/:postsLimit?', { 
name: 'nearPosts',
waitOn: function(){
return Meteor.subscribe('geo', this.params._id); //to change reference id
}
});

因此发布函数抛出错误,因为没有 loc 来获取 loc.lng

您的路线包含 /near/:postsLimit?。对于 this.params._id,您需要像 /near/:_id/near/:_id/:postsLimit? 这样的东西,这将给你们两个。参见 docs .

编辑:看起来您需要准备一些包含纬度和经度的位置数据对象以传递到您的订阅中,如下所示:

Router.route('/near/:postsLimit?', { 
name: 'nearPosts',
waitOn: function(){
return Meteor.subscribe('geo', locationObject);
}
});

由您决定使用什么 locationObject

关于javascript - 来自 sub geo id XXX TypeError : Cannot read property 'lng' of null 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31790972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com