26

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

anonymous
  • 271
  • 1
  • 3
  • 4

2 Answers2

40

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.

Mark
  • 5,499
  • 34
  • 29
  • 1
    There is no documented `.suppressMarkers` property of the DirectionsRenderer. – geocodezip Feb 03 '16 at 19:47
  • Thanks for the comment, I'm guessing that the API changed, seeing how it seemed to work for some people at first. But since the answer from @joni-jones has more up votes, it must have changed a few years ago. – Mark Feb 06 '16 at 16:36
  • Is there a way to change its position on map. I need them but not on their default position as it is conflicting with my design – Utsav Gupta Mar 02 '16 at 08:21
  • The above solution didn't work for me but this one did https://stackoverflow.com/questions/3264072/how-to-remove-default-a-b-markers-on-google-maps-route-direction . – vishal May 21 '18 at 03:51
32

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.
joni jones
  • 2,865
  • 3
  • 23
  • 28