Multiple stops along optimized route possible?

9 posts / 0 new
Last post
pawandeep_jandi...
Multiple stops along optimized route possible?

Hi, I'm new to Mapquest and wanted to know if its possible to (using multiple APIs if needed) get an optimized route with multiple locations or stops. The idea is to start and stop at the same place and visit multiple addresses in an optmized route. Its not clear if this is actually possible, but is it? Is there any guidance on how to go about solving this type of a problem? Thanks!


MQBrianCoakley
I suspect you're looking for
I suspect you're looking for the Directions API's optimized route request. Set the from (origin) and last to (destination) as the same location with waypoints between and the waypoints will be ordered to make the shortest route.

pawandeep_jandi...
Thanks for the response! I'm

Thanks for the response! I'm having some trouble implementing that call. I'm trying to format the API like this:

http://open.mapquestapi.com/directions/v2/optimizedroute?key=MY_KEY&from="SOME_ADDRESS"&to="SOME_ADDRESS"&json={"locations":["ADDRESS1", "ADDRESS2", "ADDRESS3", "ADDRESS4", "ADDRESS5",]}

But the resulting response seems to not have any mention of the first address (i.e. "SOME_ADDRESS"). Am I calling this incorrectly?


MQBrianCoakley
The key is the only parameter
The key is the only parameter that is always in the key value pair. All other request data needs to be in all kvp, json, or xml. Since there is a mix of kvp and json for the locations, one will be ignored/overridden. I also recommend using www.mapquestapi.com rather than open.mapquest.com unless there is a specific reason you're using the open version.

pawandeep_jandi...
Gotcha! I really appreciate

Gotcha! I really appreciate the help in setting this all up; so now I have my request formatted as such:

http://www.mapquestapi.com/directions/v2/optimizedroute?key=MY_KEY&json={"from":"HOME_ADDRESS","to":"HOME_ADDRESS","locations":["ADDRESS1","ADDRESS2","ADDRESS3","ADDRESS4",],}

Where the addresses are in the form: "136 S Clark Dr, Los Angeles CA, 90048".

But the response still seems to ignore to take the "from" or "to" addresses as I'm comparing this response to the route planner webpage (https://www.mapquest.com/routeplanner/) and it doesn't match up either. Am I not formatting something else properly either? 


MQBrianCoakley
When using the JSON input
When using the JSON input format, all addresses go into the locations object. There is no from or to object in the JSON input.

pawandeep_jandi...
I guess I'm confused then,

I guess I'm confused then, how does the system know that the optimized route should start and end at the same address if I don't give that specification? Is the API call supposed to look like this:

http://www.mapquestapi.com/directions/v2/optimizedroute?key=MY_KEY&json={"locations":["HOME ADDRESS","ADDRESS1","ADDRESS2","ADDRESS3","ADDRESS4","HOME ADDRESS"],}


MQBrianCoakley
The optimized route will re
The optimized route will re-arrange the locations between the first and last locations.

pawandeep_jandi...
Got it.. thanks for the help!

Got it.. thanks for the help!