If you're adamant about your geocoordinates service returning Marker
s instead of geocoordinates, then you have two options that I can think of:
a) Pass the map to the geocoordinates service
angular.module('mapGuy', function($scope, geoService) {
geoService.addMarkers($scope.map);
}).
factory('geoService', function($http) {
var addMarkers = function(map) {
$http.get('/path/to/geo/server').success(function(points) {
angular.forEach(points, function(points) {
new google.maps.Marker({
map: map, position: new google.maps.LatLng(points.lat, points.long)
})
})
});
};
return { addMarkers: addMarkers };
});
b) Stick the map on the module's $rootScope
and inject $rootScope
into the service
angular.module('mapGuy', function($scope, $rootScope, geoService) {
$rootScope.map = $scope.map;
geoService.addMarkers();
}).
factory('geoService', function($http, $rootScope) {
var addMarkers = function() {
$http.get('/path/to/geo/server').success(function(points) {
angular.forEach(points, function(points) {
new google.maps.Marker({
map: $rootScope.map, position: new google.maps.LatLng(points.lat, points.long)
})
})
});
};
return { addMarkers: addMarkers };
});
That's a rough sketch of what the code could look like. I'm pulling Google Maps API from memory, but hopefully this helps you get the idea.
I think the first option is preferable, but it's hard to say since you didn't provide a lot of context to work with.