Drawing multiple route Google Map

前端 未结 4 1227

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          


        
4条回答
  •  后悔当初
    2021-01-31 23:25

    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;
    }
    

提交回复
热议问题