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

5 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.