Extracting JSON data from routeTask

4292
4
12-18-2014 11:58 AM
HamishKingsbury1
Occasional Contributor

Hey all

 

I'm working on a network which is being solved using the routeTask api. I'm getting the resulting route displayed on the map fine but what I know want to be able to do is extract the accumulated attributes and display them in a <div> on the page.

 

The image below is showing the console with what JSON returns.

ea9b80874e.png

I've looked at the JS API documentation on the ArcGIS for Devs site as well as looking at general JS guides. I'm still relatively new to JS so i've potentially missed some more advanced code. How would I go about this?

 

Any help appreciated

 

Cheers

0 Kudos
4 Replies
TomSellsted
MVP Regular Contributor

Hamish,

Your image of the JSON didn't come through.  You should be able to get the information from the route task results.  Using the route task sample at: Simple Routing I set a breakpoint when results are displayed and drilled in to the results as shown in this image:

routeTask.fw.png

You should then be able to get the total travel time and distance from the results something like this:

totDist = evt.result.routeResults[0].route.attributes.Total_Miles;
totTravelTime = evt.result.routeResults[0].route.attributes.Total_TravelTime;

You can then use these values to update the <div>.  Be aware that routeTask results can vary depending on the parameters and the service being used.

Regards,

Tom

LinQing
New Contributor II

Hi Tom,

I have a same question. I want to calculate travel time of several routes. Here is my question.https://community.esri.com/thread/172864 Would you please have a look? Appreciated for any advice.

0 Kudos
TomSellsted
MVP Regular Contributor

Greetings Lin,

I took a look at your request and it looks like you have already solved your problem.  Well done!  Please let me know if I can be of any other assistance.

Regards,

Tom

0 Kudos
LinQing
New Contributor II

Hi Tom,

Sorry for replying you so late. Thanks for your help. I found a solution after asking you for help. There is no question now.

Thank you for the help again!

Lin

0 Kudos