SOLVED - internal Server Error 500 - unable to build isochrone map

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,

Stuart.

hi @stustokeld ,

you need to swap your coordinates from [lat,long] to [long,lat] .

Best Tahira

1 Like

Thankyou Tahira!

I now get the error - callback is not a function.

I don’t think I’m passing my data to the callback function in the correct way?

Thanks very much.

Why don’t you use axios or some other higher-level lib? A lot less pain.

1 Like

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.

If you are using java script you might want to try out the openrouteservice-js package.

Best regards

1 Like

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);

}

I am getting “drawIsochrone is not a function”

Best regards.

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.

Best regards