Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can I use HTML5 geolocation in angularjs?? I can get it using HTML55; but how can I pass it to angularjs scope in controller??? any sample jsfiddle will save my day!

share|improve this question

1 Answer 1

up vote 3 down vote accepted

you can do something

myApp.controller('fooCtrl', function($scope){
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position){
      $scope.$apply(function(){
        $scope.position = position;
      });
    });
  }
})

you need to do $scope.$apply to trigger the digest cycle when the geolocation arrives and to update all the watchers.

share|improve this answer
    
can u please help me with jsfiddle?? if u dont mind, i am a newbie to angularjs and havent used watch yet. if not, i wont mind :) –  AngryJS Apr 20 at 17:52
    
if you create a skeleton jsfiddle or plunkr i can fill this in, but you have to do some of the work yourself –  Vladimir Gurovich Apr 20 at 18:40
    
Sure, will give u skeleton one! thanks! –  AngryJS Apr 20 at 18:55
    
it worked as u suggested! thanks! :) –  AngryJS Apr 24 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.