Hi
I am new to all this. I have directions working but I cannot find how to get ORS to return how much of my quota has been used.
I am using code copied from the API documentation but I cannot see the X-Ratelimit in the response. I found that if you are using curl you need to use -d option but I cannot find what you need to do if using JavaScript.
any help gratefully received
Chris
My code follows
let request = new XMLHttpRequest();
request.open('POST', "https://api.openrouteservice.org/v2/directions/foot-hiking/geojson");
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', 'xxxxxxxxxxxxxxxxxx');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
if (this.status === 200) {
var data = JSON.parse(this.responseText);
var geometry = data.features[0].geometry;
ramblersMap.map.smartDrawLayer.clearLayers();
var latlngs = ragetLatlngs(geometry.coordinates);
var l = new L.Polyline(latlngs, {
color: '#782327',
weight: 3,
opacity: 1
});
ramblersMap.drawnItems.clearLayers();
ramblersMap.drawnItems.addLayer(l);
ramblersMap.drawnItems.fire('upload:addline', {line: l});
}
}
};
var body = {};
body.instructions = false;
body.coordinates = [];
body.geometry_simplify = true;
var i = 0;
var len = latlngs.length;
for (i = 0; i < len; i++) {
// change to long/lat rather than lat/long
body.coordinates[i] = [];
body.coordinates[i][0] = latlngs[i].lng;
body.coordinates[i][1] = latlngs[i].lat;
}
var search = JSON.stringify(body);
request.send(search);