I got a small app that use the directionservice feature of google map. It is working well, I can change routes, but I have small problem, where a user could go back to a list of markers after tracing a route.

I can't find a way to delete routes with google map. For markers I store them and do setMap(null), do not see a way here...

If you do this, it just comes back when you try to overwrite with another route, so you get both routes showing on the map.
–
ajbrausOct 27 '14 at 18:45

That's not true! I just tested in a small POC. When you run directionsDisplay.setDirections(directions) and add the renderer back to the map with directionsDisplay.setMap(map) it works correctly. It only displays one path (the contents of directions variable). There must be some other problem in your code.
–
TomikOct 27 '14 at 22:20

This is a better solution for me because if you try to get directions again the first solution will throw a JS error. However, I did directionsDisplay.setDirections({routes: []});
–
DemitryTMar 7 '12 at 17:43

1

I agree, using the literal is a better solution than the use of the new keyword, I've updated my answer.
–
AnzeoMar 9 '12 at 15:14

This didn't allow me to keep using the same map. It just stacks the routes on top of each other on the same map.
–
ajbrausOct 27 '14 at 18:46

@ajbraus It's possible the API has been changed since I answered this, I haven't checked it in a while. Please consider the date of an answer before downvoting something.
–
AnzeoOct 27 '14 at 22:21