1

我正在尝试使用 DirectionsRenderer 来显示没有路线列表的 DirectionsResult。根据 API 版本 3 文档,DirectionsRendererOptions 对象有一个“hideRouteList”属性,当设置为 true 时应该隐藏路由列表。我无法让它工作。这是一个错误还是我只是没有正确编码?以下是我的代码。

<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>
4

2 回答 2

1

试过了,我不认为你做错了什么。看起来这个选项被破坏了。我在已知问题中找不到它,所以我认为这是一个新问题。有机会我会写的。

于 2010-03-17T23:45:38.677 回答
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>
于 2011-03-25T14:02:57.093 回答