Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps: toggle destinations in directions
    text
    copied!<p>I want to toggle my directions with the help of multiple markers in google maps. Its working for single destination. After getting the directions to that single destination, if I click on any other destination marker, it is not updating with new directions. I have the following code in place: </p> <pre><code>&lt;script type="text/javascript"&gt; var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var home = new google.maps.LatLng(40.703188,-74.005029); function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var myOptions = { zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, center: home } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); directionsDisplay.setMap(map); } function calcRoute(location) { var request = { origin: home, destination: location.position, travelMode: google.maps.TravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } function getNearbyStores() { var searchQuery = $('#searchBox').val(); var request = { location: home, radius: '10000', name: [''+searchQuery] }; var service = new google.maps.places.PlacesService(map); service.search( request, callback ); var marker; function callback(results, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { var infowindow = new google.maps.InfoWindow(); var marker, i; for ( i = 0; i &lt; results.length; i++ ) { var place = results[i]; var loc = place.geometry.location; var marker = new google.maps.Marker ({ position: new google.maps.LatLng(loc.Pa,loc.Qa) }); marker.setMap(map); google.maps.event.addListener(marker, 'click', function() { calcRoute(this); }); } } } } &lt;/script&gt; </code></pre>
 

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