开发者

Google Maps API DirectionsRendererOptions not working?

I am trying to use DirectionsRenderer to display a DirectionsResult without the route list. According to the API version 3 documentation, there is a "hideRouteList" property of the DirectionsRendererOptions object that when set to true should hide the route list. I cannot get it to work. Is this a bug or am I just not coding this correctly? Following is my code.

<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.D开发者_开发百科irectionsTravelMode.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>


I tried this out and I don't think you are doing anything wrong. Looks like this option is broken. I couldn't find it in the known issues, so I think this is a new one. When I get a chance I'll write it up.


I think you're misunderstanding the documentation, or perhaps I'm misunderstanding your question!

hideRouteList:true hides route options, not the route markup. This only applies in conjunction with setting provideRouteAlternatives: true on the request object, which you've also supplied.

Below is my quick test. Set hideRouteList to true/false to see the difference in the route markup below. In my case there are no route options, but it does have different markup.

<!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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜