谷歌地图方向zero_result

时间:2018-03-14 09:29:21

标签: google-maps google-maps-api-3

方向API不适用于以下路线。总是得到ZERO_RESULT。尝试传入地址,放置ID和纬度/经度。似乎没什么用。我做错了什么或指示API在所有情况下都不起作用?

5635 Windhover Drive,Orlando,FL 32819,USA 28.486364 -81.456522
5606 Pga Boulevard APT 2518 Orlando,FL 32839 28.477603 -81.419318
905 West Oak Ridge Road APT A Orlando,FL 32809 28.473822 -81.392263

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <h1>Route Test</h1>
    <div id="map" style="width:1000px;height:1000px;float: left"></div>
    <script>
        function initMap() {
            var service = new google.maps.DirectionsService;
            var map = new google.maps.Map(document.getElementById('map'));

            // list of points
            var stations = [
                { lat: 28.486364, lng: -81.456522, name: 'Stop 1' },
                { lat: 28.477603, lng: -81.419318, name: 'Stop 2' },
                { lat: 28.473822, lng: -81.392263, name: 'Stop 3' }
            ];

            // Zoom and center map automatically by stations (each station will be in visible map area)
            var lngs = stations.map(function (station) { return station.lng; });
            var lats = stations.map(function (station) { return station.lat; });
            map.fitBounds({
                west: Math.min.apply(null, lngs),
                east: Math.max.apply(null, lngs),
                north: Math.min.apply(null, lats),
                south: Math.max.apply(null, lats),
            });

            // Show stations on the map as markers
            for (var i = 0; i < stations.length; i++) {
                new google.maps.Marker({
                    position: stations[i],
                    map: map,
                    title: stations[i].name
                });
            }

            // Service callback to process service results
            var service_callback = function (response, status) {
                if (status != 'OK') {
                    console.log('Directions request failed due to ' + status);
                    return;
                }
                var renderer = new google.maps.DirectionsRenderer;
                renderer.setMap(map);
                renderer.setOptions({ suppressMarkers: true, preserveViewport: true });
                renderer.setDirections(response);
            }

            var service_options = {
                origin: stations[0],
                destination: stations[stations.length - 1],
                waypoints: [{ location: stations[1], stopover: false }],
                travelMode: 'DRIVING'
            };

            service.route(service_options, service_callback);
        }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key={key}&callback=initMap"></script>
</body>
</html>

0 个答案:

没有答案