Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. service('currentPosition', function($rootScope){
  2. //default current position
  3. var myLocation = {lat: 59.3325800, long: 18.0649000}
  4. $rootScope.$broadcast('location', myLocation)
  5.  
  6. if ("geolocation" in navigator) {
  7. navigator.geolocation.getCurrentPosition(function(position) {
  8. myLocation.lat = position.coords.latitude;
  9. myLocation.long = position.coords.longitude;
  10. $rootScope.$broadcast('location', myLocation)
  11. });
  12. }
  13. return{
  14. getMyLocation: function(){
  15. return myLocation;
  16. }
  17. }
  18. }).
  19.  
  20. $scope.myLocation = currentPosition.getMyLocation();
  21. $scope.$on('location', function(scope,myLocation){
  22. $scope.myLocation = myLocation;
  23. });
  24.  
  25. if ("geolocation" in navigator) {
  26. navigator.geolocation.getCurrentPosition(function(position) {
  27.  
  28. $rootScope.$apply(function() {
  29. myLocation.lat = position.coords.latitude;
  30. myLocation.long = position.coords.longitude;
  31. });
  32. });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement