Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove directions from google map api v3

I have a google map using API v3 which gets directions from one location to another. The app works great but the window which gets the directions is an overlay on the map. I'd like it so when this window is closed directions are removed from the map but other markers remain.

I have tried the following:

$('#content .close').live('click', function() { $('#content').hide(); directionDisplay = new google.maps.DirectionsRenderer(); directionDisplay.suppressMarkers = true; directionDisplay.setMap(map); return false; }); 

This seems to hide the window as expected but doesn't do anything regards with removing directions from the map.

Any help is much appreciated.

Dave.

like image 480
daveredfern Avatar asked Apr 13 '11 07:04

daveredfern


People also ask

Can you customize Google Maps API?

Google Maps allows you to customize maps by adding markers manually or as a group. This method is simple and free, making it a great choice for anyone with limited experience or budget. Click on the Menu icon in the top left-hand corner. Click on the “Your Places” option in the menu.

How do I delete a map in Google Maps API?

You remove markers by using set_map(null) on the particular marker you want to clear, if you want to clear all then loop through using this function.


1 Answers

You can change the map binding for the DirectionsRenderer to "null" to remove the direction overlay

directionDisplay.setMap(null); 
like image 181
Josnidhin Avatar answered Sep 28 '22 15:09

Josnidhin