Javascript 如何删除谷歌地图路线方向上的默认 AB 标记

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3264072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:56:59  来源:igfitidea点击:

How to remove default A B markers on google maps route direction

javascriptgoogle-maps

提问by frytaz

var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();

var startMarker = new google.maps.Marker({ position: start, map: map, icon: 'start.png' });
var stopMarker = new google.maps.Marker({ position: stop, map: map, icon: 'stop.png' });

directionsDisplay.setMap(map);

var request = {
 origin: start, 
 destination: stop,
 travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function(response, status) {
 if (status == google.maps.DirectionsStatus.OK) {
  directionsDisplay.setDirections(response);
 }
});

Hi, this script shows route from start point to stop point and i use custom icons, but defaults green A and B also appear. Question is how do i remove default A and B markers so i will see only my custom ones ?

嗨,这个脚本显示了从起点到终点的路线,我使用自定义图标,但默认的绿色 A 和 B 也会出现。问题是如何删除默认的 A 和 B 标记,以便我只能看到我的自定义标记?

回答by tvanfosson

Try using the suppressMarkersoption on the DirectionsRenderer to prevent the markers on the route from being displayed. This should leave the markers that you have added directly to the map in place but not show those associated with the route.

尝试使用suppressMarkers上的DirectionsRenderer选项,以防止在路线上标记的显示。这应该会保留您直接添加到地图的标记,但不会显示与路线相关的标记。

directionsDisplay.setMap(map);
directionsDisplay.setOptions( { suppressMarkers: true } );

回答by Vaiman Hunor

directionsDisplay.setOptions({
polylineOptions: {
            strokeWeight: 4,
            strokeOpacity: 1,
            strokeColor:  'red' 
        }
});