title: How to make Google Maps V3 polyline snap to road from given points?
body: <p>I try to make a  polyline snap  to road from given marker points. My problem is, that the same 
  code sometimes gives the good results, like in this image<img src="https://i.stack.imgur.com/X8Jpz.jpg" alt="enter image description here"> </p>
  
  <p>and sometimes a bad result, like this:
  <img src="https://i.stack.imgur.com/02YXI.jpg" alt="enter image description here"></p>
  
  <p>Any ideas why this is hapenning? And also, is there a limitation for polyline snap  to road?</p>
  
  <p>My map ini code:</p>
  
  <pre><code>var myLatlng = new google.maps.LatLng(47.6557, 23.5833);
  var mapOptions = {
      zoom: 14,
      minZoom: 13,
      maxZoom: 19,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      disableDefaultUI:   true,
      overviewMapControl: false,
      streetViewControl:  false,
      scaleControl:       false,
      mapTypeControl:     false,
      panControl:         true,
      panControlOptions:{
          position: google.maps.ControlPosition.TOP_RIGHT
      },
      zoomControl: true,
      zoomControlOptions: {
          style: google.maps.ZoomControlStyle.LARGE,
          position: google.maps.ControlPosition.TOP_RIGHT
      }
  }
  var map = new google.maps.Map(document.getElementById("map"), mapOptions);
  </code></pre>
  
  <p>My  polyline route snap code:</p>
  
  <pre><code>var polys = new google.maps.Polyline({
                  map: map,
                  strokeColor: "#5555FF"
              });
      myCoord = [
                          new google.maps.LatLng(47.663383463156144, 23.58100461977301),
                          new google.maps.LatLng(47.659221287827435, 23.586240291770082),
                          new google.maps.LatLng(47.65534785438211, 23.576713085349184),
                          new google.maps.LatLng(47.66020405359421, 23.572249889548402)
              ]; 
  
      // BEGIN: Snap to road
      var service = new google.maps.DirectionsService(),polys,snap_path=[];               
      polys.setMap(map);
      placeMarker(myCoord[0], map);
      for(j=0;j&lt;myCoord.length-1;j++){            
              service.route({origin: myCoord[j],destination: myCoord[j+1],travelMode: google.maps.DirectionsTravelMode.DRIVING},function(result, status) {                
                  if(status == google.maps.DirectionsStatus.OK) {                 
                        snap_path = snap_path.concat(result.routes[0].overview_path);
                        polys.setPath(snap_path);
                  }        
              });
      }
  </code></pre>