添加多个航点Bing Maps API

时间:2014-04-30 20:16:56

标签: asp.net vb.net bing-maps

我想知道是否在编码时,有一种方法可以使用户可以这样做,因此有多个航路点。现在,我正在距离用户可以编辑的起点航点4英里处获得一个自动航路点。

这是我的代码:

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
  <script type="text/javascript">
      var map = null;
      var directionsManager;
      var directionsErrorEventObj;
      var directionsUpdatedEventObj;

      function getMap() {
          map = new Microsoft.Maps.Map(document.getElementById('myMap'), { credentials: 'myKey' });
      }

      function createDirectionsManager() {
          var displayMessage;
          if (!directionsManager) {
              directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
              displayMessage = 'Directions Module loaded\n';
              displayMessage += 'Directions Manager loaded';
          }
          alert(displayMessage);
          directionsManager.resetDirections();
          directionsErrorEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', function (arg) { alert(arg.message) });
          directionsUpdatedEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', function () { alert('Directions updated') });
      }

      function createDrivingRoute() {
          if (!directionsManager) { createDirectionsManager(); }
          directionsManager.resetDirections();
          // Set Route Mode to driving 
          {
              directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving });
              var startWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: '7500 University Dr., Bismarck, ND' });
              directionsManager.addWaypoint(startWaypoint);
              var destinationWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: document.getElementById('hometown').value });
              directionsManager.addWaypoint(destinationWaypoint);
              // Set the element in which the itinerary will be rendered
              directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });
              alert('Calculating directions...');
              directionsManager.calculateDirections();
          }
          // Insert a waypoint
          directionsManager.addWaypoint(new Microsoft.Maps.Directions.Waypoint({ address: 'Bismarck, ND'}), 1);
          // Set the element in which the itinerary will be rendered
          directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });
          alert('Calculating directions...');
          directionsManager.calculateDirections();
      }

      function createDirections() {
          if (!directionsManager) {
              Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: createDrivingRoute });
          }
          else {
              createDrivingRoute();
          }
      }          


  </script>

有没有办法可以让用户决定何时添加航点 - 这样航点不会自动,用户可以决定添加多个航点?

提前致谢。

1 个答案:

答案 0 :(得分:0)

是。您必须创建一个处理此问题的UI,而不是自动选择随机路标。然后,您只需使用addWaypoint方法将路点添加到路线管理器。