Hi, first sorry for my bad english, i hope u will understand me !

My problem :

I have to calculate the nearest point between one adresse et 8 others,
but as u can see in my code my "tabDepots[x]['id']" is always the same
because my x is really use after the route request :

here is my function :

tabDepots[][] is a global variable

function calcRoute() {
      var start = $('el-ville').get('value')+" "+$('el-
cp').get('value')+", FR";
      var end = "";
      var request = {};
      var x;
      var myRoute;
      var distance;
      var temp_distance = 2000;


    for(x = 0; x < tabDepots.length-1; x++)
    {
         end = tabDepots[x]['ville']+" "+tabDepots[x]['cp']+", FR";

        request = {
        origin:start,
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING,
        unitSystem: google.maps.DirectionsUnitSystem.METRIC
            };

            directionsService.route(request, function(response,
status) {

                if(status == google.maps.DirectionsStatus.OK) {
                 myRoute = response.routes[0];
                    distance = myRoute.legs[0].distance.value/1000;
                    if(distance <= temp_distance)
                    {
                      temp_distance = distance;

                   $('depotProche').set('value', tabDepots[x]
['id']);  // HERE tabDepots[x]['id'] is always the maximum of x
                       $('distance').set('value', temp_distance);
                    }
                }

             });
    }

  }


Is somoene have an idea ??

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to