How to build a route trough the milttiple stops using the dieectionAPI and session ID

12 posts / 0 new
Last post
vladimir63
How to build a route trough the milttiple stops using the dieectionAPI and session ID

Hello guys. Could anybody help with my issue. How to build the route and add on it several stops(4..5 adresses through which the route should be created. And where I need tp added the adresses of stops if I have adresses represented as a city name and state. Also I have a session Id getted in response from direction api.

In the end I need the pic of the map with my route on it.


MQNickZustak
Hello Vladimir,
Hello Vladimir, Good to see you here. I just wanted to let you know that I'm currently working on the best way to do this. However, to get you started, all you need to do is add the "&session=SESSION_ID" parameter to a static map request: https://developer.mapquest.com/documentation/static-map-api/v5/map/   For example, https://www.mapquestapi.com/staticmap/v5/map?key=YOUR_KEY_HERE&session=Y... I've gotten this to work with my session IDs; however, sometimes the map isn't framed correctly. The bounding box may need to be adjusted for multiple locations, and you may manually have to add the locations to the map in order to see them. I am still fiddling with this and will get back to you with the best way to utilize the static map.

MQNickZustak
Hello Vladimir,
Hello Vladimir, I'm refining the static map requests. Here's an example request: https://www.mapquestapi.com/staticmap/v5/map?key=[KEY]&session=5cd4abee-... It is relatively simple to pull the session from a previously made route request. Here's the corresponding route request I used, which returned JSON that includes the session ID: http://www.mapquestapi.com/directions/v2/route?key=[KEY]&from=Golden,%20...   In the static map request, you'll notice I have a custom Bounding Box defined. The bounding box information was pulled from the JSON result of the route request. Using the provided bounding box from the route response will assure that all locations from the route will be visible in the static map image. Let me know if I can answer anything else for you.

vladimir63
Hello hello, thx for your

Hello hello, thx for your help. It's working, but the response is with wrong bounds which cut the route in some parts. It's impossible to look at all the route. And I see in the next your response that you have solved this problem somehow. I have looked at your request and  I have a question. Can you describe this part of it plz??

 

boundingBox=39.801121,-105.225533,39.738453,-104.984856&size=838,657

what the coordinates? why it's three poitnts?? is it coordinates of the city??? and what the number of size???


MQNickZustak
Code paste
Hey again Vladimir, I pulled the boundingBox from the JSON response of the Route API. By using that boundingBox, it ensures that the static map contains the entire route. A boundingBox is made up of two points, the lat/long coordinates of the upper left corner of the box, and the lat/long coordinates of the lower right corner of the box. That third parameter you've shown is just the size of the image to be rendered; I made the size of the image to be rendered based on the window size of the user's screen. This paste of my code may help you (please excuse the mess). The code starts with the callback function that is called after making a Route API request, and then shows you how I construct the Static Map request using data (from the Route response) passed into the callback function.   https://pastebin.com/WUGnSJ4a   Let me know if you need further help.

VehpuS
Thanks for the feature + a small followup feature request

@vladimir63 - thanks for having asked for this feature

@MQNickZustak - great job on this feature. Once I got the hang on using the route API (I was focused on static maps so far) getting the route to show on my map instead of the simple lines I was drawing so far took minutes. :) Please document this capability in the docs (https://developer.mapquest.com/documentation/static-map-api/v5/getting-started) - it's a shame it's hidden here in the forums.

I do have one request regarding the feature - while displaying proper routes on the map is great, I now lost the ability to customize the markers for each locations. Specifically - I would like to be able to use the numbered labels for all stops, including the first and last. I used to do that by specifying markers for each location - perhaps this could still be a valid api?

Thanks again for the feature and thanks in advance for your help,

   Moshe


VehpuS
Clarifications after further investigation

Regarding the docs - I now see that it was documented in the full API specification, just not in the getting started section: https://developer.mapquest.com/documentation/static-map-api/v5/map/

Regarding the stops - I will clarify that after playing around with my generated query, I find that the only problem I have is with the start and end markers, stops are not marked by default and were using my own markers, just not the start and end markers.


MQBrianCoakley
Can you post the request that
Can you post the request that is not using the correct markers?

VehpuS
Still waiting for support :)

I also wanted to mention that perhaps the start / end parameters used for regular routes can be used to set these markers, if not have the location markers override the ones added for the route, as in the simple route examples: 

https://www.mapquestapi.com/staticmap/v5/map?start=New+York,NY|flag-start&end=Washington,DC|flag-end&size=@2x&key=KEY

Not sure what the api would be (maybe just a marker name, without a location?)

 

Thanks in advance :)


VehpuS
Sample request

Here is a sample pair of requests:

https://www.mapquestapi.com/directions/v2/route?key=******KEY******&from...

https://www.mapquestapi.com/staticmap/v5/map?key=******KEY******&size=50...|marker-sm-1||32.8298395,34.967313|marker-sm-2||32.8277742,34.9871949|marker-sm-3||32.8313908,34.9704919000001|marker-sm-4||32.8272398,34.9723179|marker-sm-5||32.8089933,34.9840361|marker-sm-6||32.8123726,34.9879039|marker-sm-7||32.8193413,34.9898846|marker-sm-8||32.063214,34.770737|marker-sm-9

In this case, I have a 9 step route that I'm trying to show with numbered markers, but the route's marker are given preferenece to the location markers, so the numbers 1 and 9 are not displayed.

 

Thanks again :)


VehpuS
Fixed URL formating

Pasting urls in pre tags for convenience

https://www.mapquestapi.com/directions/v2/route?key=******KEY******&from=32.811534,35.0403303000001&to=32.8325048,34.9734172999999&to=32.8325048,34.9734172999999&to=32.8298395,34.967313&to=32.8298395,34.967313&to=32.8277742,34.9871949&to=32.8277742,34.9871949&to=32.8313908,34.9704919000001&to=32.8272398,34.9723179&to=32.8089933,34.9840361&to=32.8123726,34.9879039&to=32.8193413,34.9898846&to=32.063214,34.770737&doReverseGeocode=false&unit=k
https://www.mapquestapi.com/staticmap/v5/map?key=******KEY******&size=500,500&session=5d7223cc-01f2-4ee4-02b4-234a-0a030b1b6480&boundingBox=32.832382,34.770756,32.05941,35.046436&locations=32.8325048,34.9734172999999|marker-sm-1||32.8298395,34.967313|marker-sm-2||32.8277742,34.9871949|marker-sm-3||32.8313908,34.9704919000001|marker-sm-4||32.8272398,34.9723179|marker-sm-5||32.8089933,34.9840361|marker-sm-6||32.8123726,34.9879039|marker-sm-7||32.8193413,34.9898846|marker-sm-8||32.063214,34.770737|marker-sm-9


MQBrianCoakley
The route markers from the
The route markers from the session will override the custom markers. You can use the shape from a route request and add it to the map without the session. But if the session is in the request then the origin and destination will use the default route markers.