巴林在必应地图上的过境路线

时间:2018-10-04 11:02:26

标签: javascript html bing-maps bing-api

我想在巴林地图上显示从A点到B点的公交路线。我不确定是什么问题,因为当我以“ 驾车/步行”进入路线模式时,会显示一条路径,但是当其“ 过境”时,什么都不会显示。

注意:我已从代码中的凭据中删除了地图的API密钥。

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

1 个答案:

答案 0 :(得分:1)

并非所有区域都支持运输路线。有关受支持的公交市场的列表,请参见https://msdn.microsoft.com/en-us/library/hh441739.aspx