How does alternative routes work?

I am trying to implement a feature where if the route returned does not meet the criteria of the users preferences such as the elevations ascension, it should return alternative routes. How does this work as i can not seem to get alternative_routes working in the api playground so i dont think i can get it to work when i call the API.

Is there also another option where i can get several routes on the map within a selected area?

Hey,

what errors do you get when you

?

Queries such as

curl -X POST \
  'https://api.openrouteservice.org/v2/directions/driving-car' \
  -H 'Content-Type: application/json; charset=utf-8' \
  -H 'Accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8' \
  -H 'Authorization: 5b3ce3597851110001cf6248a0ae0f6e9aa543e7b8a3960ef27626f5' \
  -d '{"coordinates":[[8.681495,49.41461],[8.687872,49.420318]],"alternative_routes":{"share_factor":0.8,"target_count":3,"weight_factor":2}}'

seem to work fine.

There is no option to get several routes within a selected area, but it shouldn’t be too hard to generate sample start and end points within an area, then route between them and check that the result lies within the area.

Best regards

Im not getting any errors, from the image below it only shows one route. Should it not display other alternative routes aswell? I am not understanding how alternative routes work, does it show other routes if the first calculated route fails to meet the requirements or does it show multiple routes on the map? I am trying to use alternative routes in my app when the first calculated route does not meet the user requirements.

Hey,

could you share your request as well?

Thanks :slight_smile:

curl -X POST
https://api.openrouteservice.org/v2/directions/foot-walking/geojson
-H ‘Content-Type: application/json; charset=utf-8’
-H ‘Accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8’
-H ‘Authorization: API KEY’
-d ‘{“coordinates”:[[8.681495,49.41461]],“alternative_routes”:{“share_factor”:0.8,“target_count”:2,“weight_factor”:2},“options”:{“round_trip”:{“length”:2000,“points”:5,“seed”:1}}}’

This request produces the image above

Hi, is there any updates on this?

Hey,

I assume that the combination of round trip and alternative_routes is what causes the problem here.
However, round trips are generated randomly anyways, so a different seed will generate a different route.

You can therefore emulate alternative_routes by varying the seed.

Best regards