gpt4 book ai didi

javascript - 我的 Meteor Geolocation 功能有问题

转载 作者:行者123 更新时间:2023-11-30 16:43:20 26 4
gpt4 key购买 nike

我无法保存坐标的纬度和经度。我在网络浏览器上进行测试,因此坐标应该可用。

  1. 我正在网络浏览器上进行测试,尝试过其他网站,在获取我的位置的经纬度方面没有任何问题
  2. lat 和 lng 出现在 {{loc.lat}}{{loc.lng}}
  3. 的 html 中
  4. 当我键入 console.log(Geolocation.latLng()); 时,它会返回正确的当前经纬度:Object {lat: xxx, lng: xxx}; 然后第二行显示 undefined 但它不可点击。
  5. 提交消息时,错误显示在命令提示符上 Exception while invoking method 'postInsert' MongoError: insertDocument::caused by::16755 Can't extract geo keys from object, malformed geometry? 并且字段显示 loc: { type: "Point", coordinates: [ null, null ] } 。我也检查了顺序是否正确。
  6. 有时它会返回此错误:Uncaught TypeError: Cannot read property 'lat' of null 由于没有提及有问题的行,因此我无法跟踪。这可能意味着 loc 为空?

有人可以帮我解决这个问题吗?提前谢谢你:)


下面是我的地理定位线

在客户端的submit.js中

    Template.postSubmit.onCreated(function() {
this.interval = Meteor.setInterval(function (){
var location = Geolocation.latLng();
if(location) {
Session.set('location', location);
};
}, 2000);
Session.set('postSubmitErrors', {});
});

Template.postSubmit.helpers({
'loc': function () {
return Session.get('location');
}
});

最佳答案

Geolocation.latLng() 触发位置的刷新,但它是异步的,因此它可能会在开始时返回 undefined,稍后返回坐标。由于 mdg:geolocation 包中没有异步回调,我使用跟踪器“等待”Geolocation.latLng() 的结果:

var userGeoLocation = new ReactiveVar(null);

Tracker.autorun(function (computation) {
userGeoLocation.set(Geolocation.latLng());
if (userGeoLocation.get()) {
//stop the tracker if we got something
computation.stop();
}
});

关于javascript - 我的 Meteor Geolocation 功能有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31608579/

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