user1611157
user1611157

Reputation: 31

Show total road distance of route on a TomTom Map

I want to retrieve the total road distance of a route between 2 locations using a TomTom map (Leaflet) and show it underneath the map... Does anyone have a working example of that?

My code so far is:

<script>
    tomtom.setProductInfo('GeoDE', '4.44.7');

    var map = tomtom.map('map', {
    key: 'myKey'
        });

    tomtom.routingKey('myKey');
    tomtom.routing({
        traffic: false
    })
        .locations('48.78270899,9.182864184:47.78270899,8.182864184')
        .go().then(function(routeJson) {
            var route = tomtom.L.geoJson(routeJson, {
                style: {color: '#0000ff', opacity: 0.6}
            }).addTo(map);
            map.fitBounds(route.getBounds(), {padding: [10, 10]});
        }); 

</script>

Upvotes: 0

Views: 275

Answers (1)

szogoon
szogoon

Reputation: 644

routeJson contains details of what you need: lengthInMeters and TravelTimeInSeconds debug screen

Upvotes: 1

Related Questions