hi there,
i am in big trouble since 2 days !
i have a $scope.greeting[] ,it is a list of deliverer in my controller ! i
want to had the distance between one origin and each deliverer in
$scope.greeting[x].distance
! i make this code :
var app = angular.module('PickleDispatch', ['ngMap']);
app.controller('gestionLivreur',function ($scope, $http, $timeout) {
$scope.getDistance = function() {
$scope.todosDests = [];
$scope.comments;
var is = 0;
for(var tous =0;tous < $scope.greeting.length;tous++) {
//todosOr[tous] =
$scope.greeting[tous].latitude+","+$scope.greeting[tous].longitude;
//todosDest[tous] =
$scope.greeting[tous].latitude+","+$scope.greeting[tous].longitude;
//alert($scope.places[tous].lat)
// $scope.places[tous].lat = $scope.greeting[tous].latitude;
// $scope.places[tous].lng = $scope.greeting[tous].longitude;
//$scope.todosDest.push(new
google.maps.LatLng($scope.greeting[tous].latitude,
$scope.greeting[tous].longitude));
//$scope.todosDest.
//alert(todosOr[tous]);
var dest =
$scope.greeting[tous].latitude+","+$scope.greeting[tous].longitude;
//originString+= new
google.maps.LatLng($scope.greeting[tous].latitude,$scope.greeting[tous].longitude)+",";
//originString= originString.substring(0,originString.length-1);
//originString= originString.substring(0,originString.length-1);
var or = $scope.origin;
var yv = 0;
$scope.googleCall(or,dest);
alert($scope.test); // *the value = undefined here*
}
};
$scope.googleCall = function(ori,desti) {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [ori],
destinations: [desti],
travelMode: google.maps.TravelMode.DRIVING,
}, function (response, status) {
if (status == google.maps.DistanceMatrixStatus.OK) {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
for (var k = 0; k < origins.length; k++) {
var results = response.rows[k].elements;
for (var l = 0; l < results.length; l++) {
var element = results[l];
var distance = element.distance.value;
googleResult.products = distance;
var duration = element.duration.text;
var from = origins[k];
var to = destinations[l];
$scope.test = distance;
alert($scope.test); // *i get the good value here*
$scope.$apply();
}
}
}
});
};
});
the problem is , i cant get any result out of the callback function ! im
looking on google since 2 days and i didnt find any solution !
your help would be grantly appreciated !
ps : i need to have it in my controller and not in the view !
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.