I am in need of retrieving a path consisting of latitude and longitudes for displaying on a map within my app.
To handle all the API calls, I have set up a basic controller.
function mainController($scope, $http){
$http.get('/api/lastrun')
.success(function(data){
$scope.lastrun = data;
})
.error(function(data){
console.log('Error: ' + data);
});
}
The 'lastrun' variable contains an array that provides access to each position along the path.
In addition, I have created a mapController using the angular-leaf-directive library.
function mapController($scope, positionService){
angular.extend($scope, {
run: {
lat: 0.0,
lng: 0.0,
zoom: 4
},
path: {
p1: {
color: 'red',
weight: 2,
latlngs: [
{ lat: 51.50, lng: -0.082 }, //example of lat and lng here
{ lat: 48.83, lng: 2.37 },
{ lat: 0, lng: 7.723812 }
]
}
}
});
}
It seems like a fairly straightforward task - simply adding the array of positions obtained from /api/lastrun into the 'latlngs' property of my mapController.
Although I do not have extensive experience with AngularJS Services, I attempted to create my own (positionService), which unfortunately did not yield the desired outcome.
If anyone has suggestions on how I can utilize my service to generate an array containing a series of {lat : , lng: } pairs and integrate it into my mapController, your assistance would be greatly appreciated.