2010-03-17 139 views
1

我正在嘗試使用DirectionsRenderer來顯示沒有路由列表的DirectionsResult。根據API版本3文檔,DirectionsRendererOptions對象的「hideRouteList」屬性設置爲true時應隱藏路由列表。我無法讓它工作。這是一個錯誤還是我只是沒有正確編碼?以下是我的代碼。谷歌地圖API DirectionsRendererOptions不工作?

<html> 
<head> 
<title>Driving Directions</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> 
<script type="text/javascript"> 
<!-- 
function initialize() { 
    var dirService = new google.maps.DirectionsService(); 
    var dirRequest = { 
      origin: "350 5th Ave, New York, NY, 10118", 
      destination: "1 Wall St, New York, NY", 
      travelMode: google.maps.DirectionsTravelMode.DRIVING, 
      unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL, 
      provideTripAlternatives: true 
    }; 
    dirService.route(dirRequest, showDirections); 
} 

function showDirections(dirResult, dirStatus) { 
    if (dirStatus != google.maps.DirectionsStatus.OK) { 
     alert('Directions failed: ' + dirStatus); 
     return; 
    } 
    var rendererOptions = { 
     hideRouteList: true 
    }; 
    var dirRenderer = new google.maps.DirectionsRenderer(rendererOptions); 
    dirRenderer.setPanel(document.getElementById('dir-container')); 
    dirRenderer.setDirections(dirResult); 
} 
--> 
</script> 
</head> 
<body onLoad="initialize();"> 
<div id="dir-container"></div> 
</body> 
</html> 

回答

1

我我認爲你沒有做錯什麼。看起來這個選項已經壞了。我在known issues找不到它,所以我認爲這是一個新的。當我有機會時,我會寫出來。

+0

在這裏登錄了一個問題 - > http://code.google.com/p/gmaps-api-issues/issues/detail?id=2247 – RedBlueThing 2010-03-17 23:49:31

0

我想你是誤解了文檔,或者我誤解了你的問題!

hideRouteList:true隱藏路由選項,而不是路由標記。這僅適用於在您提供的請求對象上設置provideRouteAlternatives:true。

以下是我的快速測試。將hideRouteList設置爲true/false,以查看下面路徑標記中的差異。在我的情況下,沒有路由選項,但它有不同的標記。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><title>Driving Directions example.</title> 
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 


    $(function() { 
     MySite.MapAdmin.init(); 
    }); 


    var MySite = {}; 

    MySite.MapAdmin = { 
     mapOptions: { 
      zoom: 14, 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      center: new google.maps.LatLng(46.51257, -84.336609) 
     }, 
     mapRendererOptions: { 
      draggable: true, 
      panel: document.getElementById('map-directions'), 
      hideRouteList: false 
     }, 
     directionDisplay: null, 
     directionsService: null, 
     map: null, 
     init: function() { 

      this.map = new google.maps.Map(document.getElementById("map"), this.mapOptions);    
      this.directionsService = new google.maps.DirectionsService(); 
      this.directionsDisplay = new google.maps.DirectionsRenderer(this.mapRendererOptions);   
      this.directionsDisplay.setMap(this.map); 

      this.plotRoute(); 

     }, 
     plotRoute: function() { 

      var selectedMode = "DRIVING"; // DRIVING, WALKING, BICYCLING 

      var request = { 
       origin: new google.maps.LatLng(46.51257, -84.336609), 
       destination: new google.maps.LatLng(46.61257, -84.336609), 
       travelMode: google.maps.DirectionsTravelMode[selectedMode], 
       provideRouteAlternatives: true 
      }; 

      MySite.MapAdmin.directionsService.route(request, function (response, status) { 
       if (status == google.maps.DirectionsStatus.OK) { 
        MySite.MapAdmin.directionsDisplay.setPanel(document.getElementById('map-directions')); 
        MySite.MapAdmin.directionsDisplay.setDirections(response); 
       } 
      }); 

     } 
    }; 


</script> 

</head> 
<body> 
    <div id="map" style="width: 800px; height: 600px;"></div> 
    <div id="map-directions"></div> 
</body> 
</html>