views:

914

answers:

8

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

+1  A: 

For each marker you want to remove, do

marker.setMap(null);

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

Matt Ball
A: 

Hello guys, have you find the solution already? The setMap(null) would be fine, but how to get the marker object of the origin and destination?

please help, thanks

Tomas
A: 

Up please

thanks

Eric
+1  A: 

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.

Dominic
A: 

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. At least that is what I believe his problem is.

anonymous
A: 

Does it remove the path for you? For me it didn't remove the path, but only the marker, path is still there as "A" --> "B"--> "C".. like wise... is there a way to remove the path? I mean clear the path, not only the markers.

Cheers, Pasan Indeewara

Pasan Indeewara
A: 

same issue...... tried reinitializing the directionsservice object, without success. reinitializing the map works, but that is not a feasible solution...

Jake