Hi,

I am looking to calculate the distance between an address and other 
addresses.
In searching the forum I found this code and I have adapted as best I could 
:

var tab_ville = array("toronto, ont", "chicago, il");  
var arrayCount = 0;  

function makeRequest(requestVar) { 
directionsService.route(requestVar, function (response,status) { 
    if (status == google.maps.DirectionsStatus.OK) { 
arrayCount ++;
if (arrayCount < tab_ville.length) { 
var nextEnd = new google.maps.LatLng(tab_ville[arrayCount][0], 
tab_ville[arrayCount][1]);
nextRequest = { 
                      origin: start, 
                      destination: nextEnd 
                  }; 
                //  recursive call to the request function 
                 makeRequest(nextRequest); 
 }
}
});
}

I have a function that calculates the distance between two fixed points, I 
would like tomerge these two codes but I do not see how

  function calcRoute() {
    var start = document.getElementById("start").value;
    var end = document.getElementById("end").value;
   /* var waypts = [];
    var checkboxArray = document.getElementById("waypoints");
    for (var i = 0; i < checkboxArray.length; i++) {
      if (checkboxArray.options[i].selected == true) {
        waypts.push({
            location:checkboxArray[i].value,
            stopover:true});
      }
  
    }
 */
    var request = {
        origin: start, 
        destination: end,
       /* waypoints: waypts,
        optimizeWaypoints: true,*/
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
     directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
        var route = response.routes[0];
        var summaryPanel = document.getElementById("directions_panel");
        summaryPanel.innerHTML = "";
        // For each route, display summary information.
        for (var i = 0; i < route.legs.length; i++) {
          var routeSegment = i + 1;
          summaryPanel.innerHTML += "<b>Route Segment: " + routeSegment + 
"</b><br />";
          summaryPanel.innerHTML += route.legs[i].start_address + " to ";
          summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
          summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br 
/>";
        }
      }
    });
  }

Thank you in advance for your help and sorry for my english I'm french.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-maps-js-api-v3/-/FytAGKUTySwJ.
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