Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple routes on google maps V3 javascript
    primarykey
    data
    text
    <p>I want to view different routes on the same map. I will load the routes from a file and put them in the two array "start" and "end". calcRoute take the array start and the end as start and end of the route. I iterate this function (in this case two time) to create the two routes. But it is viewable only the last one. I would like to see all the routes that are inside the array.</p> <pre><code>var directionsDisplay; var rendererOptions = { preserveViewport: true, draggable: false, suppressMarkers: true, polylineOptions: { map: map, strokeColor:'#FF0000', //strokeWidth: 3, strokeOpacity: 0.7} }; var start = ['Trento, via belenzani 11', 'Trento, piazza duomo'] var end = ['Trento, via belenzani 50', 'Trento, piazza pasi'] var map; function initialize() { var trento = new google.maps.LatLng(46.066712,11.119059); var myOptions = { zoom:12, mapTypeId: google.maps.MapTypeId.ROADMAP, center: trento } map = new google.maps.Map(document.getElementById("map"), myOptions); for (var i=0; i &lt; 2; i++){ calcRoute(start[i], end [i]); } directionsDisplay.setMap(map); } function calcRoute(source,destination){ // show route between the points directionsService = new google.maps.DirectionsService(); directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions); directionsDisplay.setMap(map); var request = { origin:source, destination:destination, travelMode: google.maps.DirectionsTravelMode.WALKING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } </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.
 

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