我试图通过ipinfo.io帮助显示用户位置。我创建了流星服务器方法:HTTP.get不及时提供数据
ipLocate: function() {
HTTP.get("http://ipinfo.io", function(error, result) {
var place = JSON.parse(result.content);
city = place.city;
state = place.region;
});
return [city,state];
}
它返回用户的城市和状态(但仅在第二次执行时)。
我做了一个全球性的辅助
Template.registerHelper('locationFull', function() {
// if (!Meteor.userId()) {
Meteor.call('ipLocate', function(error, result) {
response = result
Session.set('location', response);
})
return Session.get('location');
}
目前显示任何内容。
如果我手动运行客户端中的HTTP.get请求(来自我的ipLocate方法),它将返回城市和州,但只有在运行它两次后。
我怎样才能让我的城市和州在我的全球帮手页面加载返回。
除了使用mongo之外,我可以以任何其他方式存储数据吗?我正在处理用户尚未登录的应用的预先认证部分。 – chackerian