
Show HN: Trail Router – generate running routes that prefer greenery and nature - samcrawford
https://trailrouter.com/
======
samcrawford
Author here. Trail Router is a running route planner that prefers greenery and
nature in the routes it generates, and biases against busy roads. It can
generate round-trip routes that meet a specified distance, as well as point-
to-point routes.

I've written a detailed blog post about how Trail Router works here:
[https://trailrouter.com/blog/how-trail-router-
works/](https://trailrouter.com/blog/how-trail-router-works/)

I developed this because I am (or was...) a frequent traveller for work, and I
like to run wherever I visit. But I don't enjoy running on busy main roads,
and I found that without careful and time consuming route planning that is
often what would end up happening if I didn't know the area. Trail Router is
my solution to this problem.

After a previous discussion
([https://news.ycombinator.com/item?id=23177351](https://news.ycombinator.com/item?id=23177351))
received quite a lot of attention, dang reached out to suggest I post a Show
HN to reach a wider audience. I've addressed some of the original feedback too
- for example, you can now prefer hills in your routes, as well as avoid them.

~~~
pj_mukh
We sorely need this for cycling. Komoot is the closest thing but it doesn’t do
mileage requests like your app here.

This is awesome!

EDIT: In addition to optimizing for green routes, optimizing for low speed car
zones would be a killer feature.

~~~
samcrawford
Thanks! Cycling is on the to-do list. But I'm conscious it probably wouldn't
just be a single category - there would need to be separation for road cycling
and mountain biking.

The routing algorithm does already prefer roads with low speed limits, but
there is definitely more that could be done in this space (e.g. a slider to
set a preference to avoid higher speed roads). It also depends on the
availability of speed limit data (I use the OpenStreetMap database).

~~~
076ae80a-3c97-4
The state of apps/web apps for planning road cycling routes is abysmal. If you
can implement this you'll immediately be the best.

~~~
cullenking
I am curious why you think this. I run
[https://ridewithgps.com](https://ridewithgps.com) and always love
constructive feedback to improve. There’s always improvements to make, but I
wouldn’t quite go as far as calling things abysmal!

------
chrisdalke
Nice job, the algorithm is really effective! I tried this in multiple cities
where it ended up recommending very similar routes to some of my established
running routes, and even some new combinations :)

Love that your algorithm tries to exclude out-and-backs, I think that goes a
long way to make the routes feel organic and appeal to runners. This is really
polished and I wish you the best!

One feature suggestion: I wonder if you could have a flag to generate routes
starting in parking lots/park entrances in a radius around the starting
location. This could go a long way to recommend some common long-run routes
where you need to travel a brief distance via car or public transportation but
then can get 10-20 miles entirely in the woods.

~~~
samcrawford
Thanks! The avoidance of out-and-backs was a must-have for me. It can
definitely be improved though. For example, right now the algorithm tries to
avoid traversing the same path twice, but it will happily use a path that is
only a few metres away! So adding some buffer around that (to penalise paths
that are close to one already taken, if not the same) is a future bit of work.

Your suggestion is a nice one. Here in the UK, where it's common to have
trains connecting most towns and larger areas, I have thought about adding the
ability to say "I want to run 20 miles, and finish at a train station that can
get me home in under an hour". Assuming the user is using a car makes it more
easily achievable though. Consider it on the todo list!

~~~
mtnGoat
wait, it avoids out-and-backs? could have fooled me, all the routes it showed
for my house were out and backs, some had multiple points of out and back(like
a letter Y or E)... i guess thats why i hate running near home, everything is
an out and back and even the computer cant find an alternative. :)

~~~
samcrawford
It tries to! But if there's no good way to avoid them, then it will end up
taking them anyway.

More specifically, when 'avoid repetition' is enabled (it is by default), then
the routing algorithm has a very significant penalty weight applied to any
existing path already taken.

------
dang
This project was discussed in the "quarantine side project" mega-thread:
[https://news.ycombinator.com/item?id=23177351](https://news.ycombinator.com/item?id=23177351).

Since people were interested, we invited Sam to repost it.

------
codingdave
I live in a small town that is getting grown over by suburbia. The routes
ignore all the nice open farm fields to the east of me, and runs me down the
busiest streets through some of the most dangerous intersections in my entire
state, just to skim by the edge of a park in the city.

In that same 6 mile distance, in addition to running past the farms, it could
have run me up to the base of the mountains, down the nice bike trail that
goes through groves of trees and open field, then back home.

This is one reason I love testing apps like this - my town almost always
messes them up.

~~~
samcrawford
Would you mind sharing the name of your town? Feel free to email me directly
if you wish, contact details are in my profile. It could be that OpenStreetMap
data (which I use extensively in the algorithm) isn't very detailed for your
area, but I'm keen to investigate further.

~~~
codingdave
I don't mind sharing the town - Spanish Fork, UT 84660

Especially check out the east side of town, it seems like it wants to go into
town for anything short of a 15 mile loop, whereas going east is far more
natural.

~~~
samcrawford
It's not finding any green 'features' in the vicinity (I know, the mountain
range off to the east would beg to differ...), so it's falling back to
guessing a direction in which to head. I can see that the Uinta-Wasatch-Cache
National Forest is tagged properly in OpenStreetMap though
([https://www.openstreetmap.org/relation/3502235](https://www.openstreetmap.org/relation/3502235)),
so this should be something I'm able to improve on. Thanks again for your
feedback!

------
caiobegotti
Wow, I'm actually impressed by how good the results were, I was not honestly
expecting it! Lots of kudos! From the clean map interface and Strava heatmaps
to defaulting to metric units, this is something I would even pay for!

~~~
samcrawford
Quick anecdote... It defaulted to metric units globally when I first launched
it ~8 months ago. But that quickly resulted in complaints from North American
users, so it now defaults to imperial units in North America and metric
everywhere else. Users can change it in the settings menu, of course.

Thanks for the kind words!

------
jack_riminton
This is really well done, congrats. I love the level of automation to make it
so easy to use. Also the attention to UX, not just in the narrow UI sense but
the actual experience of the trail.

Some thoughts: \- Create a community out of it so that people can rate the
routes, and therefore provide feedback for the algo? \- Use some google
streetview or alternative for landmarks along the way so people remember what
they should be seeing and don't get lost?

~~~
samcrawford
UI/UX is most definitely not my forte, so I appreciate the kind words!

Your suggestion RE landmarks tallies with an issue I've been grappling with:
how does a user actually run with the route that they've just planned? Yes,
you can export the route to a GPX file, and some users will use that on
watches/apps to guide them, but it's a bit clunky and isn't the kind of thing
you'd necessarily do for a short 5km run in a new area.

I'd rather avoid building full run tracking functionality, as it'd just be
repeating what so many other apps do (and often very well). Perhaps the answer
is to enable easy syncing of the route to your other apps. Strangely, Strava
(the most popular) don't allow importing of routes via their API.

~~~
karussell
Hi Sam, instead of syncing you could hook up the GraphHopper Android
navigation demo. Although "app development" is not our focus I really like it
to test the routing in real life. And for 2.0 it will be possible to directly
have this in the server without a further dependency (see the recent pull
request). I've mostly found minor OSM problems in my neighbourhood but also
some bugs in GH.

~~~
karussell
Ah, I see you also have a mobile app. Nice! Is this mainly a mobile version or
a native app?

~~~
samcrawford
The mobile apps are really just full screen web views, with a few enhancements
on top. I will definitely check out the GraphHopper Android project and the
recent pull request. An improved native mobile app (possibly even with some
offline routing, maybe without some features) would be my ideal endgame.

~~~
karussell
The Android demo is basically a fork from Mapbox and last year or so they even
introduced offline routing (probably via valhalla), but only as a binary blob
with a closed source license attached (we forked before so this does not
affect us).

btw: are you using CH, LM or plain A* for your setup?

~~~
samcrawford
I just had a proper look at GraphHopper Navigation - I can't believe I hadn't
seen it before - that looks pretty much perfect for my use case! I will
certainly be giving that a try.

I'm using plain A* currently. I understood from the Openrouteservice
documentation & code that any time dynamic weights were being used, everything
fell back to A* anyway. And I'm using dynamic weights heavily! My
understanding could be flawed though, and I appreciate I am going to be a few
GraphHopper releases behind now. The speed is okay for now - there's certainly
bigger items on my todo list first.

I'm excited to try out GH 1.0 properly. Now that I've got much more
familiarity with what I'm doing, I'm keen to switch to using GH directly and
somehow try to avoid patching it (or try to get any patches merged back into
the open source version).

------
e15ctr0n
Love the idea. Great blog posts as well. This one alone
[https://trailrouter.com/blog/how-trail-router-
works/](https://trailrouter.com/blog/how-trail-router-works/) would have taken
you several hours to write!

~~~
rosstex
Hours? I would stress for a day on that! Bravo.

------
js2
Ha, it makes the same route planning mistake I did years ago when I was in
Rome.

I was staying near the Colosseum and for one of my runs, thought I’d run on
the Appia Antica, because oldest road in the world, into Parco della
Caffarella because it looked like a really nice park with lots of trails.

Well, next thing I know I’m running down a one-way cobblestone road with cars
coming toward me and there’s no entrance into the park because there’s a huge
wall between the road and the park. The road had walls on both sides in fact.
I didn't want to turn around because I’d have the cars to my back. So I hugged
that wall as close as I could and trusted the shit out of Roman drivers.
Eventually I found a way into the park.

Here’s the route Trail Router gave me:

• [https://ibb.co/k8m18xq](https://ibb.co/k8m18xq)

Here's the run I did that day:

• [https://ibb.co/pK6xqMX](https://ibb.co/pK6xqMX)

The road starts out looking great:

• [https://ibb.co/998GQk3](https://ibb.co/998GQk3) (my picture)

• [https://ibb.co/DYXkBt5](https://ibb.co/DYXkBt5) (google maps)

But very soon you're on this:

• [https://ibb.co/vJcCSXr](https://ibb.co/vJcCSXr) (google maps)

Well, it was all worth it because eventually I got into the park and I'm still
alive:

• [https://ibb.co/52VgT1W](https://ibb.co/52VgT1W)

• [https://ibb.co/dbvG6f5](https://ibb.co/dbvG6f5)

• [https://ibb.co/ZTPknP3](https://ibb.co/ZTPknP3)

• [https://ibb.co/VWxrwnB](https://ibb.co/VWxrwnB)

I know you're at the mercy of map data. I don't know how unique this situation
is. I always appreciate a new route planning tool. I usually use a combination
of Footpath Route Planner, the heat maps from Strava, and Google Maps street
view and satellite view. It's definitely a pain to do that for every trip.
Maps are definitely not optimized for pedestrian safety, and things like
sidewalks and shoulder-width are often inaccurate or just not there on the
maps short of bringing up street view.

~~~
samcrawford
Thanks for the feedback, appreciated. The reason it suggested that route was
(1) the park, as you found, and (2) the Via Francigena hiking route
([https://www.viefrancigene.org/en/](https://www.viefrancigene.org/en/) &
[https://www.openstreetmap.org/relation/6201614](https://www.openstreetmap.org/relation/6201614))
follows this road.

One item for consideration in the future is allowing users to flag unsafe
portions of a route and then having that visible to other users (and also
influence the algorithm).

~~~
js2
Allowing users to flag unsafe portions sounds like a good work-around.

FWIW, I'm looking at the routes it's planning from my home and they aren't
safe. It's sending me down heavily trafficked country roads with little to no
shoulder. I'll email you some screenshots.

Thanks for the new app regardless!

~~~
samcrawford
For anyone else experiencing something similar, try the 'Avoid potentially
unsafe roads' option in the settings menu. This tells the routing algorithm to
always avoid 'secondary' and 'tertiary' roads without explicit sidewalks
(these are OpenStreetMap road classifications).

This isn't on by default because in some countries/regions, such roads are
very reasonable to run on.

Clearly there's a better middle ground though, which might involve
highlighting potentially problematic parts of the route in the UI.

Thanks again js2 for your email and all your feedback!

------
danpalmer
This is fantastic. Tried it where I live and the 5km and 10km routes were very
similar to where I actually run for those distances, the only major
differences being local paths that I know of which are poorly represented in
available data.

One improvement I might suggest, it’s not clear if this is being done already,
is to not just bias towards greenery, but also boa against main roads. The
routes generated for me spent a long time on roads that are quite major, where
there are nicer alternatives available.

------
JimDabell
It seems to work well for my location. I have been living in my current home
for six months and I’ve made an effort to plan out greener routes around me
for various distances. Trail Router comes up with similar routes when I put
those distances in. It’s not perfect – it seems to prefer joining up parks
that are long distances away from one another as long as there’s a river along
the route instead of joining up parks that are closer together. But it’s a lot
better than I expected.

------
wjnc
Love the idea especially for when on holidays or in another town! I live I a
very green environment and the maps generated are quite often 'wrong', that is
not even near the routes I would suggest. Preferring urban areas to non-urban
areas and seemingly not knowing of major walking paths in the forests nearby.
The Strava map seems to know those paths, but OSM probably doesn't. Anybody
know where I can dive deeper in OSM to find out what's going on?

An example: my neighborhood is surrounded by a free laying cycling and walking
path. Perhaps diametrically only 30m-100m from houses, but 100% green and
rustic. Then the mapper plots a route on sidewalks in urban areas. It did
recognize the no. 1 park around though. But I'd hope it would get the woods as
well.

~~~
samcrawford
Thanks! My suggestion would to start out by checking out your area on
openstreetmap.org for two things: Firstly to check to see if the trail you
refer to is shown (it should show up as a yellow dashed line if it's a trail).
Secondly to see if the woods are shown (this should show in a light green
shaded area). Trail Router uses the presence of woods as a hint to prefer
paths. Both of these items are surprisingly easy to edit on OSM.

------
saeranv
This is great. I move around a lot, and one of the big headaches I always have
is figuring out a decent route to run. The only thing I would request is
having an option to have completely circular routes, rather then having routes
that require running back the way you came.

------
hobofan
Looks very nice! Just started out running and especially the feature that it
outputs multiple routes of similar lengths (which I can slowly increase) to
have some variation is very appealing! From what I can see the routes all look
very runnable with a lot of greenery.

------
egypturnash
I am looking at the route it is generating from my place in New Orleans and
comparing it against my own mental route generator for cycling and it’s not
doing so well. It’s got me running _parallel_ to Jeff Davis Parkway instead of
taking the trail along the very green parkway, then up the side of Bayou St.
John with the _least_ greenery (one side has a lot, the other has next to
none). Maybe in part because the unofficial desire trails up the green side of
the bayou that I regularly see joggers on don’t seem to exist on the map.
Going though City Park makes sense; coming back I guess Cortez isn’t too bad a
choice if “avoid repetition” is on, but avoiding Jeff Davis just seems super
weird.

------
necovek
Pretty neat!

I did see a problem with stairs — not sure if algorithm does not take into
consideration or if data is not properly marked up in OpenStreetMap, but
locally, it recommended a route goong over two long sets of stairs: one of
them being practically a goat trail I would recommend against running on, but
careful trodding is ok. The other stairs are long and wide, so probably not
perfect for running (hard to figure out your stride), but ok. I wonder if
elevation rate could be taken into account, which would probably exclude the
goat trail one.

~~~
samcrawford
Steps are supported in OSM, but I don't know if your ones in particular are
tagged. Either way, Trail Router doesn't consider them by default. If there is
a lot of elevation gain/loss when using the stairs, you can adjust the Hill
Preference slider (in the settings screen) to indicate whether you prefer
hills or would rather avoid them. You can read more about that here:
[https://trailrouter.com/blog/greenery-and-hills-
sliders/](https://trailrouter.com/blog/greenery-and-hills-sliders/)

------
ak217
This is awesome! I've tried it on a few areas that I know well, and it really
did a good job.

I really love running in new places as a way to explore my area as well as
when I travel. I find there is something profoundly good about connecting with
my surroundings that way. I use Strava Route Planner with the heatmap
extensively, and now I think I'll be consulting this a lot.

My only suggestion is to show an elevation profile. There is already a hill
preference slider in the settings, but the elevation profile would really make
it great to look at.

~~~
samcrawford
You're in luck, both of those things are already supported!

For viewing the elevation profile, click on the little up arrow on the
miles/km distance box at the bottom of the screen.

You can configure a hills preference (either to prefer them or to avoid them)
in the settings screen. Click on the cog icon to get there. More details are
available at [https://trailrouter.com/blog/greenery-and-hills-
sliders/](https://trailrouter.com/blog/greenery-and-hills-sliders/)

------
knownhoot
this is AMAZING! very fast and planned some interesting routes in Portland
that I hadn't thought of. I think i'll start using this over my premium strava
route planner

------
subpixel
As a runner who only runs on trails (e.g. not on pavement) I make a point of
asking other runners about places to run before I visit a new town.

I tend to get great advice and the benefit is that I often meet people to
follow on Strava, where I build up a library of potential runs.

I’m not looking forward to a future where every conceivable off-road trail is
available, instantly, in an app. I doubt anyone who appreciates nature really
is.

------
jwineinger
I just loaded this and the map was centered on my house before I gave access
to my location. I'm using current Firefox. Anyone know how that would happen?

~~~
samcrawford
It uses geoIP data from Maxmind to approximately locate users even before they
provide location information. It's not usually _that_ accurate though. It's
just intended to get a user to the rough location that they're based in.

------
ogre_codes
This is pretty cool, but there are definitely routes that pop up quickly that
cross closed gates and trails that are not in good repair. I'd consider these
to be good "Beta" routes, if you enjoy exploring and don't mind the occasional
dead-end, but not super reliable if your time is limited.

Not a complaint, if I ran these are the sort of routes I'd love to explore.

~~~
samcrawford
That's very fair, thanks. In cities I wouldn't consider this to be much of an
issue as an occasional dead end (e.g. road works) is easily manually avoided.
But in more rural locations it can be frustrating. If you're seeing it in your
area, then you could consider submitting a correction to OpenStreetMap. It's
surprisingly easy to do. I update Trail Router with the latest OSM data
roughly once per month.

------
sicromoft
This is really well done. If you use this, please consider donating. (I'm not
affiliated in any way, I just saw on the about page that it's self funded and
costs $200/mo). Here's the patreon page:
[https://www.patreon.com/trailrouter](https://www.patreon.com/trailrouter)

------
ganstyles
This is cool! Strava has a new feature where they'll plan a route for you:
give a mileage range and a starting spot. When you tell Strava to prioritize
trails vs paved, you get good results. Interesting very similar to yours, so
that's really impressive given they're a large company with a big budget, or
perhaps it says more about my location.

------
jamgraham
AllTrails has a free trail creation tool. Check it out here, you just need to
create a free account to save.

[https://www.alltrails.com/explore/map/new](https://www.alltrails.com/explore/map/new)

------
3guk
Thanks for creating this, just tried it in my local area and it generated a
route that I already enjoy !! I shall no doubt get a lot of use out of this,
whilst it’s not the intended use - I will cycle a few of the routes over the
next few weeks !

------
etrautmann
This is an amazing tool, I just downloaded the app and am excited to use it
routinely. Thank you!

------
seattle_spring
This is really fantastic. Thanks for making this!

One suggestion: Have changes to the route push state to the history. That way
you can use the back button on the browser if you make a mistake. Right now
it'll totally take you off of the page.

~~~
samcrawford
Thanks very much! Personally I find it a little annoying if a site pushes
state to the history very frequently. If I genuinely want to get off the site
I end up clicking back loads, and then go too far!

I tried to solve this in Trail Router by putting an undo button on the screen
(bottom right).

~~~
seattle_spring
I would just follow how Google Maps works. I think that's how my brain was
expecting Trail Router to work, since it visually and functionally is very
similar to using the "Directions" feature of GMaps.

------
tinus_hn
It’s quite amazing these days there’s enough free data and software available
you can create such a tool on your own! How do you plan to make it pay the
server costs though?

~~~
samcrawford
Fully agreed - the amount of data openly available is astounding. I think many
people would be surprised at the richness of the tagging information within
OpenStreetMap. Without OpenStreetMap, this project and countless others would
not be possible.

Mapping costs would be by far the biggest one. However, I'm very lucky that
after the last big spike in traffic, Mapbox very generously admitted me to
their community programme. You can read more about that here:
[https://trailrouter.com/blog/mapbox-community-
programme/](https://trailrouter.com/blog/mapbox-community-programme/)

The server costs are quite modest at the moment (under $200/mo), which I'm
lucky enough to be able to self-fund through my other work. If usage were to
massively increase then maybe I'd need to find a way recoup costs. But even
all of the hits from HN have barely put a dent in the server utilisation, so
there's plenty of headroom for the foreseeable future.

------
aloisdg
I love to see that you rely a lot on open source. Using OSM instead of gmaps
is a big plus in my list. Do you also plan to open source it?

------
WD-42
Nice work! I tried it out for my local area and it ended up suggesting some
routes that are very similar to my existing runs/rides.

------
annoyingnoob
Looks interesting. It missed the multi-use trail that wraps around the area
where I live - though its not on google maps either.

~~~
samcrawford
It may be that the trail near you isn't on OpenStreetMap
([https://openstreetmap.org](https://openstreetmap.org)). If you're interested
in fixing that (and thus the myriad of tools that rely on OpenStreetMap data),
head to
[https://wiki.openstreetmap.org/wiki/Getting_Involved](https://wiki.openstreetmap.org/wiki/Getting_Involved)

------
senden9
I tried to generate a 10km round trip route. It generated exactly the same
route that I run normally :D

------
lostpixel
Looks interesting! Have you considered providing a way to sync routes directly
to Running watches?

~~~
samcrawford
I actually have. Watch this space - there should be direct route syncing to
Garmin and Suunto before terribly long. In the meantime, you can export routes
to GPX/KML files already.

------
jordwest
Wow. As soon as I gave it my location it plotted my favourite local return
hike, very cool!

------
voisin
Is there a way to show the elevation associated with a route?

~~~
samcrawford
Yes - click on the little up arrow in the mile/km distance box at the bottom
of the screen. It will show you elevation, as well as the type of paths taken.

------
steven_pack
Nice job! Two clicks on my phone and first route was spot on.

------
baq
very cool! i live close to a forest and it found a trail i had to manually
tune on komoot.

feature request: an option to not cross country borders would be nice.

------
sandos
Id want this but for bicycles.

------
christiansakai
This gonna be a hit!

