Set a startpoint in JavaScript for Directions

Hello,

I use the Directions service. How can I enter a starting point?

I have embedded a javascript in an html page and need to specify a start point when passing it.

The function looks like this:

let request = new XMLHttpRequest();

request.open('POST', "https://api.openrouteservice.org/v2/directions/driving-hgv/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', 'api-key');

request.onreadystatechange = function () {
 if (this. readyState === 4) {
 console.log('Status:', this.status);
 console.log('Headers:', this.getAllResponseHeaders());
 console.log('Body:', this.responseText);
 }
};

const body = '{"coordinates":[[7.4578615,53.4836767],[8.686507,49.41943],[8.687872,49.420318]], "language": "de-de"}';

request.send(body);

Thank you for your help.

See you
Ralf

Hi @Ralf_Nowak,

  • The coordinates array should contain all points for the route.
  • The first coordinate is the starting point.
  • The last coordinate is the end point.
  • Any coordinates in between are waypoints that are visited in order.
"coordinates": [
  [longitude1, latitude1],  // Start point
  [longitude2, latitude2],  // Waypoint 1
  [longitude3, latitude3],  // Waypoint 2
  [longitudeN, latitudeN]   // End point
]

Best regards