Itinéraire avec plusieurs adresses

301 views
Skip to first unread message

Essohana Alayi

unread,
Feb 9, 2012, 10:40:47 AM2/9/12
to google-map...@googlegroups.com
J'ai écris une fonction Javascrispt qui permet de tracer un itinéraire à partir d'un ensemble d'adresses mais je suis confronté à un problème. le problème c'est que je ne peux pas dépasser dix (10) adresses. Au secours!
la fonction est la suivante:
//string en tableau
 function stringSplit(ch)
     {
        var reg=new RegExp("[#]+", "g");
        //document.write("Chaîne d'origine : " + ch+ "<BR>");
        var tab=new Array();
        var tableau=ch.split(reg);
        tab=ch.split(reg);
       
        return tab;
     }
function route()
    {
     var i;            
          /*var reg=new RegExp("[#]+", "g");
          var tableau=chaine.split(reg);*/   
     function destinationtAd(_adress)
      {
      this.adresse = _adress;   
      }    
     
      // déclaration des variables
      var chaine=document.getElementById('Adr').value;
      var tableau=stringSplit(chaine); //appel fonction split
      var destinationCoord=new Array;
      for (i=0; i<tableau.length  ; i++) {   
         destinationCoord[i] = new destinationtAd(tableau[i]);
        }
         var lat = new Array;
         var lng = new Array;
         
         for(i = 0 ; i < tableau.length ; i++)
         {
         //var Coord =
         var geo=geolocalise(destinationCoord[i].adresse);
         
         pausecomp( alert("longitude :"),2000);
         
         lat[i] = latitude;
         lng[i] = longitude;
         }                        
         

      if (origin == null) {
        origin = new google.maps.LatLng(lat[0], lng[0]);
        addMarker(origin);
      }
     
      if (destination == null) {
        destination = new google.maps.LatLng(lat[1], lng[1]);
        addMarker(destination);
      }         
     
      i = 2;
   
    do{
          waypoints.push({ location: destination, stopover: false});
          destination = new google.maps.LatLng(lat[i],lng[i]);
          addMarker(destination);
          i++;
       
        }while(i < tableau.length);
       
        if (origin == null) {
      alert("Click on the map to add a start point");
      return;
    }
   
    if (destination == null) {
      alert("Click on the map to add an end point");
      return;
    }
  
    var request = {
        origin: origin,
        destination: destination,
        waypoints: waypoints,
        travelMode: google.maps.DirectionsTravelMode.DRIVING,
        optimizeWaypoints: document.getElementById('optimize').checked,
        avoidHighways: document.getElementById('highways').checked,
        avoidTolls: document.getElementById('tolls').checked
    };       
   
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);   
     }   
    });
   
    clearMarkers();
    directionsVisible = true;
}   
       
        function pausecomp(millis)
            {
            var date = new Date();
            var curDate = null;

            do { curDate = new Date(); }
            while(curDate-date < millis);
            }        
   
         function geolocalise(addr) {
        
            geocoder.geocode({'address': addr }, function (results, status) {
                 /* Si g?ocalisation r?sie */
                 if (status == google.maps.GeocoderStatus.OK) {
                     /* R?p?tion des coordonn? */
                     latitude = results[0].geometry.location.lat();
                     longitude = results[0].geometry.location.lng();  
                     
                 }
             }); 
                    
         }
     
  function addMarker(latlng) {

    markers.push(new google.maps.Marker({
      position: latlng,
      map: map,
      clickable: true,
      icon:new google.maps.MarkerImage('bus.png')
    }));   
  }
Prière de jeter un coup d'oeil. Merci pour votre aide.

Paul

unread,
Aug 1, 2012, 6:06:04 AM8/1/12
to google-map...@googlegroups.com
There is a limit to the google directions service:
Reply all
Reply to author
Forward
0 new messages