Removing Directions markers from the Google Maps API V3

anonymous picture anonymous · May 28, 2010 · Viewed 27.3k times · Source

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)?

Answer

Mark picture Mark · Jun 1, 2010

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.