Thanks for your response. Yes, I have tried to use this property, however, I cannot seem to get the properties associated with each individual route by name. I only specify the routeName value for the stops, and am not really sure how this associates with each route segment. Each route is solved using the following:routeTask.solve(routeParams);map.graphics.add(solveResult.routeResults[0].route.setSymbol(routeSymbol));I can also display the route name and distance in the same alert box using:var routeLength = solveResult.routeResults[0].directions.totalLength;var routeName = solveResult.routeResults[0].routeName;var routeNameLength = routeName +" "+routeLength;Do you have any suggestions on how to correspond the name of each route to the length as far as returning a variable is concerned?
routes[solveResult.routeResults[index].routeName] = solveResult.routeResults[0].directions.totalLength
var routes = {};
var distance = routes["your_route_name"];
This method worked like a charm. Thanks alot for your help!
You can use a Javascript object in a hastable-like manner. For exemple, inside a loop for your routeResults you could use:routes[solveResult.routeResults[index].routeName] = solveResult.routeResults[0].directions.totalLengthIn the previous sample, index is the for loop indexer and you need to previously declare de routes object (before the loop):var routes = {};After that, you can get the total length of a specific route by using its name as an indexer for the routes object:var distance = routes["your_route_name"];
Have you consider to use the routeName property of each RouteResult instance?
I have a route task that is calculating multiple routes simultaneously. When the user clicks on a map, a stop is added and draws different routes for up to seven different locations. I have assigned every stop a route name and each route is drawing properly to the appropriate stops. I need to return the total length of each individual route as a variable for input into a function and was wondering what would be the best way of going about this. I can successfully alert box the lengths of each route by using: var routeInfo = solveResult.routeResults[0].directions.totalLength; alert(JSON.stringify(routeInfo)); However, the order that each alert message displays starts with the shortest distance routes first. How do I need to go about identifying which distance is associated with each route? Thanks in advance.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.