Praesagus
Praesagus

Reputation: 2094

Google Maps Version 3 Remove directions markers

Is there any way to remove the markers that the directions put on the map? I have 4 locations that show on the map. A green arrow where the user is and 3 locations marked A, B, C. If I click on one it routes between the user's location and the marker. The problem is that google adds a new A & B marker to the map as the start and end of the directions. Now I have a couple A and B markers on the map and it's pretty confusing.

Thanks

Upvotes: 1

Views: 7008

Answers (6)

anonymous
anonymous

Reputation: 271

Normally you'd be able to simply do marker.setMap(null), but because the Directions call automatically places the A & B markers on the map, you do not have direct access to them and therefore cannot remove them in this way.

Upvotes: 0

bobetko
bobetko

Reputation: 5168

This is an old post, but I ran on the same issue. I have map with my own markers, I would select few of them and starting point, then I would show directions with markers A, B, C... The problem was how to remove directions and show my markers again.

Here is what worked for me to remove direction paths with markers (A, B, C, etc..).

directionsDisplay.setMap(null);
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
RefreshMarkers(); //your function to draw your markers

directionDisplay is declared globally. It's API v3.

Upvotes: 2

marc wolf
marc wolf

Reputation: 11

Hit menu then layers and on the lower left press clear map. That should clear out everything on the map.

Upvotes: 1

Matty F
Matty F

Reputation: 3783

In the DirectionsRendererOptions set suppressMarkers to true

Upvotes: 9

Dominic
Dominic

Reputation: 419

Not sure if this is helpful or not. When you create a new GDirection and supply it with a map object, it will automatically draw the polyline to the map as soon as the direction is loaded. This also automatically adds the markers at the start and end of the journey.

I've noticed, however, that if you don't supply the map object initially and instead use the the 'load' event listener to manually add the polyline to the map, you get the line but not the markers.

//Don't supply a map to GDirections()
var direction = new GDirections(); 

//Make sure {getPolyline:true} is given to the load function
direction.load("here to there", {getPolyline:true});

GEvent.addListener(direction, 
                   "load", 
                   function(){ map.addOverlay(direction.getPolyline()); }
);

This might be easier than finding and removing the markers, especially if you're using the 'load' event listener anyway.

Upvotes: 1

Matt Ball
Matt Ball

Reputation: 359816

For each marker you want to remove, do

marker.setMap(null);

http://code.google.com/apis/maps/documentation/v3/overlays.html#Markers

Upvotes: 1

Related Questions