Removing Directions markers from the Google Maps API V3

纵饮孤独 提交于 2019-11-29 00:43:32

问题


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


回答1:


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.




回答2:


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.

来源:https://stackoverflow.com/questions/2932416/removing-directions-markers-from-the-google-maps-api-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!