【问题标题】:HTML5 getCurrentPosition with MeteorHTML5 getCurrentPosition 与 Meteor
【发布时间】:2012-05-02 22:08:07
【问题描述】:

我正在尝试将 html5 地理位置 API 与 Meteor 一起使用。 我正在使用: navigator.geolocation.getCurrentPosition(handle_geolocation_query); 在我的 js 中,但它似乎不起作用 - 我认为这可能与 Meteor 的计时器(http://docs.meteor.com/#timers)限制有关。有什么想法吗?

【问题讨论】:

  • 我想不出这些冲突的原因。我刚才在我的流星应用程序中测试了地理定位,以确保一切正常。你在用处理程序做什么?可能是处理程序正在尝试访问尚未完成加载的数据。

标签: html geolocation meteor


【解决方案1】:

感谢@lashleigh,这是加载问题

这是对我有用的代码(我正在使用 Modernizr.js 来检测地理位置)

if (Meteor.is_client) {
  Session.set('loc','?');
  //alert(Modernizr.geolocation);

  function foundLocation(location) {
    console.log(location);
    Session.set('loc','lat: '+location.coords.latitude+', lan: '+ location.coords.longitude);
  }
  function noLocation() {
    alert('no location');
  }
  Template.hello.greeting = function () {
    var output;
    if (Modernizr.geolocation) {
      navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
      outpout = Session.get('loc');
    }
    return Session.get('loc');
  };
}

【讨论】:

  • 甜蜜!很高兴你能解决这个问题。
猜你喜欢
  • 2010-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-27
相关资源
最近更新 更多