在我的meteor应用程序中,我试图在
中设置用户位置Meteor.startup(() => {...}
像这样:
navigator.geolocation.getCurrentPosition((succ) => Session.set('currentLocation',succ));
但是,当稍后在应用程序中尝试访问它时,它会返回一个空对象。 我验证了设置静态会话变量,如'hi',它工作正常。我还验证了使用console.log(succ)调用回调,这也可以正常工作。我最好的猜测是会发生一些会话变量的覆盖,我无法弄清楚如何测试它。
有什么想法吗?
答案 0 :(得分:3)
请查看此文章Meteor Session
位置获取代码
navigator.geolocation.getCurrentPosition(success, error);
function success(position) {
Session.set("Latitude",position.coords.latitude);
Session.set("Longitude",position.coords.longitude);
}
function error() {
console.log("unable to retrive your location");
}
和Retrive会话数据
let Latitude = Session.get("Latitude");
let Longitude = Session.get("Longitude");
注意:仅会话工作客户端。