2

I want to display the transit route from point A to B on the Bahrain map. I'm not sure what the issue is because when I entered the route mode as "driving/walk" a path is displayed but when its "transit" nothing shows up.

Note: I have removed my map's API key from the credentials in the code.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />

    <script type='text/javascript' 
            src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap' 
            async defer></script>

    <script type='text/javascript'>
        var map;
        var directionsManager;

        function GetMap()
        {
            var map = new Microsoft.Maps.Map('#myMap', {
            credentials: '',

        });

            //Load the directions module.
            Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
                //Create an instance of the directions manager.
                var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

                //Calculate a date time that is 1 hour from now.
                var departureTime  = new Date();
                departureTime.setMinutes(departureTime.getHours() + 1);

                //Set Route Mode to transit.
                directionsManager.setRequestOptions({
                    routeMode: Microsoft.Maps.Directions.RouteMode.transit,
                    time: departureTime,
                    timeType: Microsoft.Maps.Directions.TimeTypes.departure
                });

                //Add waypoints.
                var w1 = new Microsoft.Maps.Location(26.230570, 50.577430);
                var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ location: w1 });
                directionsManager.addWaypoint(waypoint1);

                var w2 = new Microsoft.Maps.Location(26.227840, 50.494110);
                var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ location: w2 });                
                directionsManager.addWaypoint(waypoint2);


                //Set the element in which the itinerary will be rendered.
                directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });

                //Calculate directions.
                directionsManager.calculateDirections();
            });
        }
    </script>
</head>
<body>
    <div id="myMap" style="position:relative;width:800px;height:600px;"></div>
    <div id='directionsItinerary'></div>
</body>
</html>
Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50

1 Answers1

1

Transit routing is not supported in all areas. For a list of supported transit markets, see https://msdn.microsoft.com/en-us/library/hh441739.aspx

Duncan Lawler
  • 1,772
  • 8
  • 13