I'm displaying a list of places on a map using the google places api. Users can get directions to each of those places individually. The directions appear on the map fine and everything works, but each time they get directions to a different place it adds it to the map along with the old one(s). I want to overwrite the existing directions on the map when a new place is selected. So only one set of directions appear at anyone time. Ideally, I only want one route marked on the map and the one list of directions displayed.
I've tried adding the the following to clear all directions before I set the new ones:
directionDisplay = new google.maps.DirectionsRenderer();
directionDisplay.suppressMarkers = true;
directionDisplay.setMap(null);
As suggested here: Google Maps Version 3 Remove directions markers but to no avail.
No matter how much googling and search through the documentation I just can't seem to get it.
Any help would be greatly appreciated.
JA
There is no need to clear the directions before rendering new ones.
Use 1 global variable for directionDisplay, the current directions will be removed as soon as you call setDirections() to render new directions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With