I'm using a promise within map
function and I want to assign every element of array; latitude and longitude properties. Here's the code for example:
$scope.dataset = response.map(function(item, index) {
GeoCodingService.query({
address: item.country
}).$promise.then(function (response) {
item.latitude = response.results[0].geometry.location.lat;
item.longitude = response.results[0].geometry.location.lng;
console.log(item);
//result {id: "au", count: 593, country: "Australia", latitude: -25.274398, longitude: 133.775136}
});
console.log(item);
//result {id: "au", count: 593, country: "Australia"}
});
console.log($scope.dataset);
//result [undefined, undefined, undefined, undefined, undefined]
My goal is to obtain all the results with latitude and longitude where I get undefined i.e. in $scope.dataset variable.