Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to plot multiple markers as well as plot a route between two points?
    primarykey
    data
    text
    <p>Is it possible to plot multiple markers as well as plot a route between two points?</p> <p>Ive succeeded in doing it separately. But how can it be done in the same map? </p> <p>When i combine the two, route plotting is not getting done, however the markers are getting plotted.</p> <p>What ive done so far is below : </p> <pre><code> var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var locations = [ ['Bondi Beach', -33.890542, 151.274856, 4], ['Coogee Beach', -33.923036, 151.259052, 5], ['Cronulla Beach', -34.028249, 151.157507, 3], ['Manly Beach', -33.80010128657071, 151.28747820854187, 2], ['Maroubra Beach', -33.950198, 151.259302, 1] ]; var infowindow = new google.maps.InfoWindow(); var marker, i; for (i = 0; i &lt; locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map }); google.maps.event.addListener(marker, 'click', (function (marker, i) { return function () { infowindow.setContent(locations[i][0]); infowindow.open(map, marker); } })(marker, i)); } directionsDisplay = new google.maps.DirectionsRenderer(); directionsDisplay.setMap(map); var start = new google.maps.LatLng(-33.890542, 151.274856); var end = new google.maps.LatLng(-34.028249, 151.157507); var request = { origin: start, destination: end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function (response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(-33.92, 151.25), mapTypeId: google.maps.MapTypeId.ROADMAP }); </code></pre> <p>HTML : </p> <pre><code> &lt;div id="map-canvas"&gt;&lt;/div&gt; </code></pre> <p>Script: </p> <pre><code> &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"&gt;&lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload