2013-12-12 49 views
1

我已經使用谷歌地圖API的Transit層進行了應用程序。我的應用程序頁面如下所示: 當我創建路線時,我得到了兩件我想要的東西從地圖擦除。 1)我使用suppressMarkers成功移除的標記A B。在谷歌地圖api中刪除運輸路線的車輛信息

2)圖片中的白色信息窗口向我提供有關使用的路線種類和所用服務的信息,可在this鏈接中看到。 就像我要刪除的孟買CST-Kalyan窗口

我無法找到如何刪除它們。請指導。

+0

你試過[suppressInfoWindows](https://developers.google.com/maps/documentation/javascript/reference#DirectionsRendererOptions)嗎? – geocodezip

+0

@geocodezip:我試着使用suppressInfoWindows,但它仍然沒有擦除infowindow。我這樣做: 'var directionsDisplay = new google.maps.DirectionsRenderer(({suppressMarkers:true,suppressInfoWindows:true}));' – Neeti

+1

這不是一個infowindow它是過境信息。我不相信它可以被刪除,除非你自己渲染路線。 – geocodezip

回答

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(); 

     } 
    }); 
}