2017-02-20 31 views
2

我使用的是下面的代碼。我只想計算優化路線和總駕駛時間的距離。任何人都可以幫助我得到這個。計算mapquest中的距離和持續時間

<script type="text/javascript"> 
    // download the module 
    var map = new MQA.TileMap(document.getElementById('map')); 
    MQA.withModule('new-route', function() { 
     // uses the MQA.TileMap.addRoute function to pass in an array 
     // of locations as part of the request parameter 
     var opt = { 
      request: { 
       locations: ['Gunnison, CO', 'Ouray, CO'], 

       options: { 
        avoids: [], 
        avoidTimedConditions: false, 
        doReverseGeocode: true, 
        shapeFormat: 'raw', 
        generalize: 0, 
        routeType: 'fastest', 
        timeType: 1, 
        locale: 'en_US', 
        unit: 'm', 
        enhancedNarrative: false, 
        drivingStyle: 2, 
        highwayEfficiency: 21.0 
       } 
      }, 

      display: { 
       color: '#800000', 
       borderWidth: 10 
      }, 

      // on success, display the route narrative 
      success: function displayNarrative(data) { 
       if (data.route) { 
        var legs = data.route.legs, 
       html = '', 
       i = 0, 
       j = 0, 
       trek, 
       maneuver; 

        html += '<table class="clean"><tbody>'; 

        for (; i < legs.length; i++) { 
         for (j = 0; j < legs[i].maneuvers.length; j++) { 
          maneuver = legs[i].maneuvers[j]; 
          html += '<tr>'; 
          html += '<td>'; 

          if (maneuver.iconUrl) { 
           html += '<img src="' + maneuver.iconUrl + '" />'; 
          } 

          for (k = 0; k < maneuver.signs.length; k++) { 
           var sign = maneuver.signs[k]; 

           if (sign && sign.url) { 
            html += '<img src="' + sign.url + '" />'; 
           } 
          } 

          html += '</td><td>' + maneuver.narrative + '</td>'; 
          html += '</tr>'; 
         } 
        } 


        html += '</tbody></table>'; 
        document.getElementById('route-results').innerHTML = html; 
       } 
      } 
     } 
     map.addRoute(opt); 
    }); 
</script> 
+0

更新爲從格式化塊中遺漏的格式代碼。 –

回答

0

如果你需要的是路線的時間和距離,跳過映射工具(尤其是上面,因爲它會在日落2018年6月所使用的),並直接使用directions api。每個路線響應將包括時間和距離。 A route matrix只會有時間和距離。