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
add comment

1 Answer

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 16 hours ago
    
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 15 hours ago
    
Sure, will give u skeleton one! thanks! –  AngryJS 15 hours ago
add comment

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.