How can I use HTML5 geolocation in angularjs? I can get it using HTML5; but how can I pass it to angularjs scope in controller? any sample jsfiddle will save my day!
Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
Join them; it only takes a minute:
|
you can do something
you need to do $scope.$apply to trigger the digest cycle when the geolocation arrives and to update all the watchers. |
|||||||||||||||||
|
I'd suggest abstracting this into a service so your controller doesn't have a dependency on window.navigator, and to avoid the unnecessary use of $scope.$apply(). Here's what I'm using in my project:
Then I consume it in my controller like this:
|
|||||
|
You can use
|
|||
|
Due to firefox's issue not getting feedback from user on prompting that website needs to access your location when user clicking "Not now", X or outside prompt box (more here), below is a tiny example to trigger fallback action for this case. Plunker
And your app js.
|
|||||
|