Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Directions markers from the Google Maps API V3

To remove a normal marker from a map, I understand you simply call marker.setMap(null), but when implementing the Google Maps directions services, it automatically adds markers A and B onto the map ( calculating directions from point A to point B ). I do not have control over these markers, so I cannot remove them in the normal way. So how can I remove these markers (I have custom markers on the map instead)?

like image 767
anonymous Avatar asked May 28 '10 20:05

anonymous


2 Answers

Set the suppressMarkers option to true when creating your DirectionsRenderer object and then the markers won't show up. You could also change the style or icon of the markers. See the API spec for DirectionsRendererOptions for other properties you can set.

   ... 
   directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
   ...

EDIT: It looks like the API changed a little bit since my original answer almost 6 years ago, so the answer from @joni-jones is now the correct way. I tweaked my example above to reflect that.

like image 173
Mark Avatar answered Oct 19 '22 20:10

Mark


I had a similar problem. The previous solution did not help me. But I tried this:

var directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
And it's work.
like image 41
joni jones Avatar answered Oct 19 '22 19:10

joni jones