Guest User

gmapapi

a guest
Jul 21st, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.27 KB | None | 0 0
  1.                     for ( i = 0 ; i < locations.length; i++ )
  2.                     {
  3.                         var marker = locations[i][5];
  4.                         var name = locations[i][0];
  5.                        
  6.                         directionsService.route
  7.                         (
  8.                             {
  9.                                 origin: <?php echo "'$zip'"; ?>,
  10.                                 destination: new google.maps.LatLng(locations[i][2],locations[i][3]) ,
  11.                                 travelMode: 'DRIVING'
  12.                             }, function(response, status)
  13.                             {
  14.                                 if (status === 'OK')
  15.                                 {
  16.                                     var directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
  17.                                     directionsDisplay.setMap(map) ;
  18.                                     directionsDisplay.setDirections(response);
  19.                                     directionDisplays.push(directionsDisplay) ;
  20.                                     alert(name);
  21.                                     google.maps.event.addListener(marker, 'click', (function(marker, i)
  22.                                     {
  23.                                         return function()
  24.                                         {
  25.                                             var point = response.routes[ 0 ].legs[ 0 ];
  26.                                             infowindow.setContent('<b><center>' + name + '</center></b><br>' + '<b>Temps estimé:</b> ' + point.duration.text + '<br><b>Distance: </b>' + point.distance.text);
  27.                                             infowindow.open(map, marker);
  28.                                         }
  29.                                     })(marker, i));
  30.                                 }
  31.                                 else
  32.                                 {
  33.                                     window.alert('Directions request failed due to ' + status);
  34.                                 }
  35.                             }
  36.                         );
  37.                        
  38.                     }
Add Comment
Please, Sign In to add comment