google-maps-api-3 - 使用谷歌地图 api 隐藏最后一个方向标记

标签 google-maps-api-3 markers direction

我用 map api 计算了一条起点和终点相同的路线。

因为起点和终点相同,所以第一个标记与最后一个标记重叠。现在我只想删除最后一个标记。

我只知道如何隐藏它们:

directionsDisplay.suppressMarkers = true;

有没有办法遍历标记并删除最后一个标记?

这是我用于指示的代码:

function calcRoute(waypts) {
    var start = waypts[0].location;
    var end = waypts[0].location;


       var request = {
        origin:start,
        destination:end,
        waypoints:waypts,
        optimizeWaypoints: true,
        provideRouteAlternatives:false,
        travelMode:google.maps.TravelMode.DRIVING
       };

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

           directionsDisplay.suppressInfoWindows = true;
           directionsDisplay.suppressMarkers = true;
           directionsDisplay.setDirections(response);

           console.log(status);

    }else{
         alert('SATUS:'+response.status);

    }
 });
}

最佳答案

试试这个

初始化中

directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});

然后

directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var route = response.routes[0];
    var start =route.legs[0].start_location;
    var end =route.legs[0].end_location;
    addMarker(end);

添加标记函数

    function addMarker(pos){
var marker = new google.maps.Marker({
  position: pos, 
  map: map, 
  icon: 'images/your image'

}
)
}

我还没有测试过这个,但你应该明白了

关于google-maps-api-3 - 使用谷歌地图 api 隐藏最后一个方向标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9635805/

相关文章:

python - 使用matplotlib无法完全显示无花果边界处的标记

javascript - api 中的 Google map 旅行模式

c# - 在 ASP.NET 中处理服务器端数据的 Javascript

google-maps-api-3 - KML ARGB 颜色显示不正确

javascript - 实现自定义标记 - jsartoolkit5

pandas - 如何将数据从两列传递到使用 folium 制作的等值线图标记的弹出标签?

javascript - ag-Grid 禁用水平填充句柄

javascript - 从多个子组件的 componentDidMount() 同步更新父组件状态

c# - 如何从鼠标坐标获取基本鼠标方向

javascript - 为什么 Google map 服务器需要访问客户端浏览器中添加的 KML 图层?