[英]Calculating distance and duration in mapquest
I am using the code below. 我正在使用下面的代码。 I just want to calculate the distance of the optimized routes and total driving duration.
我只想计算优化路线的距离和总行驶时间。 Can anyone help me to get this.
谁能帮我得到这个。
<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>
If all you need is the time and distance of routes, the skip the mapping toolkit (especially the one used above since it will be sunset in June 2018) and use the directions api directly. 如果您只需要路线的时间和距离,请跳过映射工具包(尤其是上面使用的工具包,因为它将在2018年6月日落),然后直接使用Directions api 。 Each route response will include the time and distance.
每个路线的响应将包括时间和距离。 A route matrix will ONLY have time and distance.
路线矩阵仅包含时间和距离。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.