I’m sending a request for isochrones using an XMLHttpRequest in Javascript, and I’m getting a “500” internal server error.
The response payload in my console looks like this - {“error”:{“code”:3099,“message”:“Unable to build an isochrone map.”},“info”:{“engine” {“version”:“5.0.2”,“build_date”:“2019-11-14T08:11:08Z”},“timestamp”:1576152104549}}
My request is
function walkRequest(url, callback) {
console.log("here");
let request = new XMLHttpRequest();
request.open('POST', "https://api.openrouteservice.org/v2/isochrones/driving-car");
request.setRequestHeader('Accept', 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', 'MY_API_KEY_HIDDEN');
//set an event listener for when the HTTP state changes
request.onreadystatechange = function () {
//a successful HTTP request returns a state of DONE and a status of 200
if (request.readyState === 4 && request.status === 200) {
callback(JSON.parse(request.responseText));
}
};
const body = '{"locations":[[-2.23179, 53.464774],[-2.23185, 53.464780]],"range":[300,200]}';
request.send(body);
}
function callback (data){
console.log(data);
}
Is there something wrong with my request?
Thanks in advance,
hi @stustokeld,
If you want to calculate for manchester, your coordinates have to be swapped.
You are currently calculating for a point in the indian ocean.
Thanks @amandus, I have swapped the coordinates and I am now having trouble passing the response to my callback function in order to add it to my leaflet map.
//set an event listener for when the HTTP state changes
request.onreadystatechange = function () {
//a successful HTTP request returns a state of DONE and a status of 200
if (request.readyState === 4 && request.status === 200) {
// Trying to do is pass the request.response to a callback function to style it
drawIsochrone(request.response);
}
};
const body = '{"locations":[[-2.23179,53.464774],[-2.23185,53.464780]],"range":[300],"range_type":"time"}'
request.send(body);
};
function drawIsochrone (data) {
console.log(data);
}
Hi @stustokeld,
sorry, but this is a basic javascript/ programming problem not an ORS topic.
Just search around the web a bit and you can solve this on your own.