GIScience / openrouteservice-js

:pushpin: The JavaScript API to consume openrouteservice(s) painlessly!
https://openrouteservice.org
Apache License 2.0
192 stars 35 forks source link

Directions geojson format problem #13

Closed stefanocudini closed 5 years ago

stefanocudini commented 5 years ago

I use this code:

var Ors = Npm.require('openrouteservice-js');

var directions = new Ors.Directions({
    api_key: '<MY_SECRET_KEY>'
});
directions.calculate({
    instructions: false,
    coordinates: [[10.88476896,45.92084111],[10.89092731,45.92013953]],
    format: 'geojson'
})
.then(function(json) {
    console.log('then', json)
})
.catch(function(err) {
    console.warn("error",err);
});

that produce this request:

POST /v2/directions/foot-hiking/geojson HTTP/1.1
Host: api.openrouteservice.org
Accept-Encoding: gzip, deflate
User-Agent: node-superagent/4.1.0
Content-Type: application/json
Authorization: <MY_SECRET_KEY>
Accept: application/json
Content-Length: 186
Connection: close

{"instructions":false,"coordinates":[[10.88476896,45.92084111],[10.89092731,45.92013953]],"preference":"fastest","units":"m","language":"en","geometry":true,"instructions_format":"text"}

but is show an exception:

{"error":{"code":2007,"message":"This response format is not supported"}

I think the problem is Accept: application/json instead of Accept: application/geo+json A simple patch is in this PR: https://github.com/GIScience/openrouteservice-js/pull/14

TimMcCauley commented 5 years ago

Fixed with #14