在google maps api中删除公交路线的车辆信息

时间:2013-12-12 09:21:16

标签: javascript google-maps google-maps-api-3

我使用Google Maps API的Transit层创建了一个应用程序。我的应用程序页面如下所示: 当我创建路线时,我得到两件我想要从地图上删除的东西。 1)使用suppressMarkers成功移除的标记A B。

2)图片中的白色信息窗口,提供有关所用路线类型和所用服务的信息,可在this链接中查看。 就像我想要移除的孟买CST-Kalyan的窗口一样

我无法找到如何删除它们。请指导。

1 个答案:

答案 0 :(得分:1)

如果您像本例一样呈现自己的方向,那么这些方向就不会出现。

  function calcRoute() {
    polyline.setMap(null);
    var start = document.getElementById("search1").value;
    var end =  document.getElementById("search2").value;
    var request = {
      origin: start,
      destination: end,
      travelMode: getSelectedTravelMode()
    };

    polyline = new google.maps.Polyline({
      path: [],
      strokeColor: '#FF0000',
      strokeWeight: 3
    });

    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        var bounds = new google.maps.LatLngBounds();
        var route = response.routes[0];
        var summaryPanel = document.getElementById("directions_panel");
        var detailsPanel = document.getElementById("direction_details");
        startLocation = new Object();
        endLocation = new Object();

        summaryPanel.innerHTML = "";
        detailsPanel.innerHTML = '<ul>';

        // For each route, display summary information.
        for (var i = 0; i < route.legs.length; i++) {
          var routeSegment = i + 1;
          summaryPanel.innerHTML += "<b>Route Segment: " + routeSegment + "</b><br />";
          summaryPanel.innerHTML += route.legs[i].start_address + " to ";
          summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
          summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br />";
        }
    var path = response.routes[0].overview_path;
    var legs = response.routes[0].legs;
        for (i=0;i<legs.length;i++) {
          if (i == 0) { 
            startLocation.latlng = legs[i].start_location;
            startLocation.address = legs[i].start_address;
            createMarker(legs[i].start_location,"start",legs[i].start_address,"green");
          }
          endLocation.latlng = legs[i].end_location;
          endLocation.address = legs[i].end_address;
          var steps = legs[i].steps;
          for (j=0;j<steps.length;j++) {
            var nextSegment = steps[j].path;
            detailsPanel.innerHTML += "<li>"+steps[j].instructions;
            var dist_dur = "";
            if (steps[j].distance && steps[j].distance.text) dist_dur += "&nbsp;"+steps[j].distance.text;
            if (steps[j].duration && steps[j].duration.text) dist_dur += "&nbsp;"+steps[j].duration.text;
            if (dist_dur != "") {
              detailsPanel.innerHTML += "("+dist_dur+")<br /></li>";
            } else {
              detailsPanel.innerHTML += "</li>";

            }
            for (k=0;k<nextSegment.length;k++) {
              polyline.getPath().push(nextSegment[k]);
              bounds.extend(nextSegment[k]);
            }
          }
        }

        detailsPanel.innerHTML += "</ul>"
        polyline.setMap(map);
        map.fitBounds(bounds);
        createMarker(endLocation.latlng,"end",endLocation.address,"red");
        // == create the initial sidebar ==
        makeSidebar();

      }
    });
}