I would like to draw multiple routes based on the directions service in Google, the code goes below
p/s:Data is a list I obtained from my json call
for
If you have everything else set up, but are only getting one route to show up on your map, the problem is likely that you are not resetting the DirectionsRenderer
to null
before reusing it.
Each DirectionsRenderer
can only be used to render one route. So if you are cycling through an array and creating a variable like renderer
each time, you have to make sure to reset it to null
and create a new one.
For example
for (all routes){
directionsRenderer = new google.maps.DirectionsRenderer(optionsDictionary);
//call route(), define call back function, etc.
directionsRenderer = null;
}