Select to view content in your preferred language

Display Total Mileage on 'Find a route and directions' tool

523
1
2 weeks ago
rVeloz
by
Occasional Contributor

good morning. i am trying my hand at the js maps sdk. i was able to create a simple app using this tutorial: https://developers.arcgis.com/javascript/latest/tutorials/find-a-route-and-directions/. My app works to create a route from 2 clicks, with turn-by-turn directions and mileage for each turn. 

BUT i would like to display the TOTAL MILEAGE from Location1 to Location2. Is there a way to add that in the setup from this tutorial?

thanks in advance for any guidance.

0 Kudos
1 Reply
Noah-Sager
Esri Regular Contributor

Hi @rVeloz, thanks for posting your question here. To add that information from that tutorial, you need to use the "result" object, around line 128 if you pop the tutorial into Codepen. To prove this, you can add a couple statements like this to print-out the info to the browser Console:

console.log("route length (miles): ", result.route.attributes.Total_Miles);
console.log("route length (kilometers): ", result.route.attributes.Total_Kilometers);

Here is a slightly modified version of the tutorial to test. Just supply your API Key and open the browser Console and run the app.
https://codepen.io/noash/pen/ogjdWOB?editors=1000

 

0 Kudos