I’m developing a feature for a hiking application where you can create a route plan, let’s say between A-B, and the user can create a round trip (by adding B-A), where it is guaranteed that the return trip won’t be the same as A-B. So no matter how much more time is needed, the return trip should be a different route.
I started to play with algorithm=alternative_route
but the problem is that I rarely get alternative routes in hiking areas, the returned paths
array contains only one item most of the times.
I tweaked the following params but did not find a combination which gave me more than one path for some hiking routes:
alternative_route.max_paths
alternative_route.max_weight_factor
alternative_route.max_share_factor
Is there a way to force the directions API to give me at least 2 alternative routes?
Example route:
Thanks in advance.
There is no way to force alternatives, but you could try ch.disable=true
and as it uses a different “alternative route” algorithm it might give other/more alternatives.
Please note that this approach is not always fully functional as sometimes there are oneways (even for walking routes) and the B-A route could be wrong.
Due to this and also other reasons (like quality) we have an option algorithm=round_trip
which should fit your requirements best.
I was thinking about using round_trip
, but as I know it allows only one starting point and you can tweak it by round_trip.distance
and heading
, so it is not guaranteed that the result route will contain A-B points which the user defined.
Let’s say the user placed A-B-C markers. What I can do is
- use
round_trip
with one starting point A
- calculate the distance between A-B-C-A and use it as
round_trip.distance
- get heading from A-B so at least the starting direction will be the same
But even with the above setup it is not guaranteed that GH will give me a round trip which uses A-B-C points.
Is this correct or am I missing something?
Can you describe your use case? Is it that the user wants to reach a destination but wants to avoid the same route when going back?
Yeah that’s the reason, because in hiking trips if you reached your destination you usually don’t want to go back in the same route as you arrived, most of the people are looking for round trips.
This feature is meant to be only for convenience like “I want to reach peak X but don’t want to come back in the same route because that is boring”