13 posts / 0 new
Fri, 05/26/2017 - 16:03#1
Generate list of states route passes through
I need to generate a list of states the my route passes through. Is there any default functionality that will do this or a recommended approach?
E.g I have a route that goes through 6 states. I need to generate a list including all of those states.
Thank you for both replies. Here and Stack.
Do you offhand know of a way to obtain the distance traveled in each state?
States routed through Colorado, Nebraska.
Colorado: 123.5miles, Nebraska 567.2 miles
I'm thinking if I can retrieve a lat/long for each state boundary I can then build separate state routes.Basically break the full route down in to pieces. Use the stateBoundaries as start/finish for each state. What do you think?
90% will be done server side with Php.
Form (A-B addresses) -> Processed via Php, Curl (post) request fastest route
Display Map, Drag route
Confirm changes -> Php process -> Curl (post) request directions
Php process state mileage
Display static map and data.
Form (Startpoint address, Endpoint address...various other data) -> Php.
Php inserts form data to DB -> outputs page -> MQ API displays route (leaflet).
Client Drags new route -> JS passes Data.Route "string" [JSON.stringify(data.route)] to form -> Client submits final route form.
Php parses form -> Loops through data.route and compiles total mileage per state (data.route.legs.0.maneuvers -> narrative,distance)
Mileage, data.route etc updated in db record -> display state based mileage and various other bits of data.
No additional calls to the API are required. The manuevers->distance value is used alongside the manuevers->narrative "Crossing into" substring to determine stop/start points for new state boundaries. The accuracy of the state mileage is based on the assumption that the execution of the "Crossing into" manuever will put you in the new state.
Simply put the manuever states: (Crossing into Ohio) and the distance for that manuever is 4.89 miles. At the end of that 4.89 miles, you are infact in Ohio.
I will be posting this information and code on StackOverflow. If the mods have no objection I will post a link in this thread once I get it on SO.
Where is the link to his code, I would love to examine to see I can find anything useful that can be applied to my application.
Sorry everyone for the late reply.
I ran into a snag with the "stateBoundaryDisplay" and pushed it to the back burner.
Basically the problem is on some routes the Directions data does not include a "Crossing into" string for each state indepently. e.g. (Crossing into Iowa). It will combine multiple states in a single Crossing string.
The problem route Was Oregon to Ohio. (Oregon > Idaho > Utah > Wyoming > Nebraska > Iowa > Illinois > Indiana > Ohio)
So the first state for mileage calculation is Oregon (start point). The first "crossing into" string would stipulate the end of mileage calculation for Oregon (crossing into Idaho) and the start of the next state mileage calculation (Idaho).
The directions passed the following boundaries:
Until a "Crossing into" string is passed for each stateBoundary this approach is pretty much dead in the water.