0

The direction API does not work for the following route. Always get ZERO_RESULT back. Tried passing in addresses, place ids, and lat/long. Nothing seems to work. I am doing something wrong or does the directions api just not work in all cases?

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>
Zed
  • 11
  • 1
  • 2
  • 1
    What doesn't work? What do you get in your javascript console? Does the API work in all cases? Certainly not. It doesn't work in some areas/countries. It certainly has limitations. – MrUpsidown Mar 14 '18 at 10:21
  • 1
    For some reason change your waypoint code to `stopover: true` and it will work. Just tried it with different API versions and I get the same results. This is strange. – MrUpsidown Mar 14 '18 at 10:42
  • 1
    thank you so much, stop overs work. I read the other question and they say 'U-turn maneuver is not allowed' without. Thanks again – Zed Mar 20 '18 at 17:52
  • Interesting. I didn't know that and that seems to explain this behavior. – MrUpsidown Mar 21 '18 at 08:34

0 Answers0