Sessions created by Alternate Routes API not immediately available to Static Map service

4 posts / 0 new
Last post
dtrebbien
Sessions created by Alternate Routes API not immediately available to Static Map service

I am experiencing an intermittent issue with sessions created by the Alternate Routes API not being immediately available to the Static Map service.

Here is a demo:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(function () {
var key = "MY_KEY";
$.ajax({
dataType: "json",
url: "https://www.mapquestapi.com/directions/v2/alternateroutes?key=" + encodeURIComponent(key) + "&callback=?",
method: "POST",
data: {
maxRoutes: 10,
from: "1000 Throckmorton Street, Fort Worth, TX 76102",
to: "1520 K Avenue, Plano, TX 75074",
options: {
shapeFormat: "cmp"
}
},
success: function (data) {
var routes = [data.route];
if (data.route.alternateRoutes != null) {
for (var i = 0; i < data.route.alternateRoutes.length; ++i) {
routes.push(data.route.alternateRoutes[i].route);
}
}

for (var i = 0; i < routes.length; ++i) {
var route = routes[i];
var pElem = document.createElement("p");
var imgElem = document.createElement("img");
imgElem.src = "https://www.mapquestapi.com/staticmap/v4/getmap?key=" + encodeURIComponent(key) + "&size=425,400&bestfit=" + encodeURIComponent(route.boundingBox.ul.lat + "," + route.boundingBox.ul.lng + "," + route.boundingBox.lr.lat + "," + route.boundingBox.lr.lng) + "&session=" + encodeURIComponent(route.sessionId);
imgElem.style.width = "425px";
imgElem.style.height = "400px";
pElem.appendChild(imgElem);
document.body.appendChild(pElem);
}
}
});
});
</script>

What this JS does is request alternate routes between two locations and then immediately add <img> elements for static maps displaying the alternate routes found.  Occasionally I will see that the static map generated by the Static Map service is missing the purple route shape, which is specified by passing the session ID returned by the Alternate Routes API.

I observed this issue frequently on September 7, but September 8 through 10, the issue appeared to be fixed.  This morning I re-ran my demo and saw the issue re-appear.

I have developed a work-around.  However, I am concerned about possible URL length issues.

Can you remove the asynchronous delay between when sessions created by the Alternate Routes API are made available to the Static Map service?


MQBrianCoakley
Are you seeing a delay in the
Are you seeing a delay in the session? Or does the session just not work at all - even after some period of time?

dtrebbien
It's a delay.  Eventually the

It's a delay.  Eventually the purple route line will appear if I keep refreshing the static map.  However, it can take several seconds before the session is available (up to ~20 seconds), and I do not have an indication of whether the purple route line is visible for a particular static map.


MQBrianCoakley
Thanks for the information. I
Thanks for the information. I'm forwarding this on to the development team.