Google Maps API DirectionsRendererОпции не работают? - PullRequest
1 голос
/ 18 марта 2010

Я пытаюсь использовать DirectionsRenderer для отображения DirectionsResult без списка маршрутов. Согласно документации API версии 3, существует свойство «hideRouteList» объекта DirectionsRendererOptions, которое при значении 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>

Ответы [ 2 ]

1 голос
/ 18 марта 2010

Я попробовал это , и я не думаю, что вы делаете что-то не так. Похоже, эта опция не работает. Я не смог найти его в известных проблемах , так что я думаю, что это новый. Когда у меня будет шанс, я напишу об этом.

0 голосов
/ 25 марта 2011

Я думаю, вы неправильно понимаете документацию, или, возможно, я неправильно понимаю ваш вопрос!

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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...