How do I pass geo location data around in Angular JS?

So basically I'm building an angular/ionic app that is heavily location based, basically every feature requires geo location of the user. I'm trying to wrap my head around providing the location data from the user to forms, controllers etc. I understand that the call to get the user's loc is like this below(which is a callback).

 Navigator.geolocation.watchPosition(function (pos) {
      var latLng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
  }, function (error) {
      alert('Unable to get location: ' + error.message);
  });

Basically how do I pass around the result of this the user's location and utilize it for various other functions? Do I need to duplicate this code snippet in every place where I want the user's location("notice it's in watch mode to detect changes")

Thanks a lot.

You should put that code in a service or factory, and then inject it into your controllers as needed.

Create a factory and have the promise resolve the latLng.

.factory('Local', ['$q', function($q){
  return {getLocation: function(options){
    var q = $q.defer();
    navigator.geolocation.watchPosition(function (pos) {
    var latLng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
    q.resolve(latLng);
 }, function (error) {
  q.reject(error)
 }, options);
    return q.promise;
  }

}
}])

Then you can inject the factory into wherever you need it.