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);
}
});
嗨,此脚本显示从起点到终点的路线,我使用自定义图标,但默认绿色A和B也会出现。 问题是如何删除默认的A和B标记,以便我只看到我的自定义标记?
答案 0 :(得分:85)
尝试使用DirectionsRenderer上的suppressMarkers选项,以防止显示路线上的标记。这应该将您已直接添加到地图中的标记保留在原位,但不显示与路径关联的标记。
directionsDisplay.setMap(map);
directionsDisplay.setOptions( { suppressMarkers: true } );
答案 1 :(得分:4)
directionsDisplay.setOptions({
polylineOptions: {
strokeWeight: 4,
strokeOpacity: 1,
strokeColor: 'red'
}
});
答案 2 :(得分:0)
map = new google.maps.Map(document.getElementById("mapCanvas"), mapOptions);
directionsRenderer.setMap(map);
directionsRenderer.setOptions( { suppressMarkers: true } );