Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 getCurrentPosition with Meteor

I'm trying to use the html5 geolocation api with Meteor. I'm using: navigator.geolocation.getCurrentPosition(handle_geolocation_query); in my js but it doesn't seem to work - I think it may be related to the timer ( http://docs.meteor.com/#timers ) restrictions Meteor has. Any thoughts?

like image 948
Gavriguy Avatar asked Nov 23 '25 14:11

Gavriguy


1 Answers

Thanks @lashleigh it was a loading problem

Here is the code that worked for me (I'm using Modernizr.js to detect geo-location)

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');
  };
}
like image 139
Gavriguy Avatar answered Nov 25 '25 03:11

Gavriguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!