logo
Blog single photo

waypoints | Directions Service | Maps JavaScript API


                        

List Of DirectionsRequest

{
  origin: LatLng | String | google.maps.Place,
  destination: LatLng | String | google.maps.Place,
  travelMode: TravelMode,
  transitOptions: TransitOptions,
  drivingOptions: DrivingOptions,
  unitSystem: UnitSystem,
  waypoints[]: DirectionsWaypoint,
  optimizeWaypoints: Boolean,
  provideRouteAlternatives: Boolean,
  avoidFerries: Boolean,
  avoidHighways: Boolean,
  avoidTolls: Boolean,
  region: String
}

Example Code

<script src="https://maps.googleapis.com/maps/api/js?key=YOURAPI&callback=initMap&sensor=false"></script>
<div id="map" style="height: 400px; width: 100%;"></div>
<script type="text/javascript">
    var directionsService = new google.maps.DirectionsService;
    var directionsRenderer = new google.maps.DirectionsRenderer;
    var locations = [['S.D.F., GP Block, Sector V, Bidhannagar,
    Kolkata, West Bengal 700091, India', 22.56895178447658, 88.430597482979, 1],
    ['Ultadanga Foot Bridge, CIT Scheme VII M, Ghose Bagan, Kolkata, West Bengal
    700054, India', 22.59142709886644, 88.39305881606208, 1],
    ['PNB BA 1, BA Block, Sector 1, Bidhannagar, Kolkata, West Bengal 700064,
    India', 22.59131090322868, 88.39961555545503, 1],['Korunamoyee Sclupture,
    DJ Block, Sector II, Bidhannagar, Kolkata, West Bengal 700091, India',
    22.5863232178235, 88.42169601004076, 1],];
    var image = {url:'http://tobuekalabya.com/carservice_manage/images/8077.png',
        scaledSize : new google.maps.Size(50, 50),
    };

    var map = new google.maps.Map(document.getElementById('map'),
    {
      zoom: 12,
      center: new google.maps.LatLng(22.5863232178235,88.42169601004076),
      mapTypeId: google.maps.MapTypeId.ROADMAP
     
    });
    directionsRenderer.setMap(map);

    var start = "Ultadanga Main Rd, Murari Pukur, Ultadanga, Kolkata,
    West Bengal 700067, India";
    var end = "S.D.F., GP Block, Sector V, Bidhannagar, Kolkata, West Bengal 700091,
     India";
   
    directionsService.route({
        origin: start,
        destination: end,
        waypoints: [{location: 'S.D.F., GP Block, Sector V, Bidhannagar, Kolkata,
        West Bengal 700091, India, OK',stopover: true},
        {location: 'Ultadanga Foot Bridge, CIT Scheme VII M, Ghose Bagan, Kolkata,
        West Bengal 700054, India, OK',stopover: true},
        {location: 'PNB BA 1, BA Block, Sector 1, Bidhannagar, Kolkata, West Bengal
        700064, India, OK',stopover: true},
        {location: 'Korunamoyee Sclupture, DJ Block, Sector II, Bidhannagar, Kolkata,
        West Bengal 700091,
        India, OK',stopover: true},],
    travelMode: 'DRIVING'
    }, function(response, status) {
        if (status === 'OK') {
        directionsRenderer.setDirections(response);
        } else {
        window.alert('Directions request failed due to ' + status);
        }
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: image
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
  </script>

See More Google Map Directions Service

Top