I am trying to use the directions service of ORS and I want to know if what I am trying to achieve is possible and to know how to set the parameters correctly to get the desired output.
I want to get the shortest path from point A to B and I don’t want to take into account any traffic rules. Take for
instance the following example:
I have two questions that I would like to ask (corresponding to the numbers in the image):
- Sometimes the coordinates that are used are located in the middle of a field. Is it possible to also visualise the line between the point on the map and the shortest way to the road and to also take this into account in the calculated distance?
- Is it possible, that if the route that follows the road is way longer than a route through the green, to make the route go through the green? I have tried to use {“profile_params”:{“weightings”:{“green”:{“factor”:1}}}}, but that didn’t do it.
I am eager to hear from you! Thanks in advance.
Younes
Javascript code:
var request = new XMLHttpRequest();
request.open('GET', 'https://api.openrouteservice.org/directions?api_key=5b3ce3597851110001cf6248c057ebe63f0a4775b34a2ce3885d5221&coordinates=5.603635,53.10476%7C5.616580,53.10950&profile=foot-walking&preference=shortest&options=%7B%22profile_params%22:%7B%22weightings%22:%7B%22green%22:%7B%22factor%22:1%7D%7D%7D%7D');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
request.send();