2

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>
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Hema
  • 21
  • 3

1 Answers1

0

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. Each route response will include the time and distance. A route matrix will ONLY have time and distance.

MQBrian
  • 452
  • 1
  • 3
  • 7