'Get route from a coordinate to a random distance

I have this specific use case I can't figure out how to implement.

I need to trace a route route from a starting point to a random distance from that point.

The goal is to for instance suggest a route to the users can take if they want to walk 10km from their starting point or any point on a map.

Any ideas? or is there any free/paid service for such usecase?

Thank you for your help



Solution 1:[1]

One approach you could try is creating an isodistance polygon, then randomly choosing a direction from the center and find the intersection with the shape.

This blog post generates an isodistance shape by calculating the distance to a grid of nearby points, then producing a concave hull around the perimeter.

https://blog.mapbox.com/dive-deeper-into-isodistances-c90bd5df9215

You could then randomly select a direction and draw a line to intersection that shape. One approach to that is to draw a line from the center to north, and then http://turfjs.org/docs/#transformRotate a random angle.

Then use https://turfjs.org/docs/#lineIntersect to find the intersection point.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mikel Maron