Find better bicycle routes with new Valhalla options

Valhalla, Mapzen’s free and open source routing and navigation engine, has been updated with an assortment of bicycle navigation enhancements. You can now influence the path of the bicycle route and the estimated travel time by including optional costing settings for the type of bicycle, your speed, or whether you want to ride on streets with traffic.

By specifying the bicycle type in a query to the routing service API, Valhalla can suggest more appropriate routes and accurate times for you. While some kinds of bicycles are designed only for paved surfaces, others also work well on gravel and dirt paths, and Valhalla can route and estimate accordingly. Each bicycle type has a default cycling speed, which is intended to be what an average rider can comfortably maintain over the length of the route. You may ride faster or slower than the defaults, so you can now override the speed with your own value.

For example, if you are riding a road bike (a lightweight bicycle with narrow tires), you want your route only to follow paved surfaces. Perhaps you also want to take a slower-paced trip and minimize riding on roads where you must travel with cars.

The JSON for this query might look something like this:

valhalla.mapzen.com/route?json={"locations":[{"lat":34.413,"lon":-119.859},{"lat":34.412,"lon":-119.846}],"costing":"bicycle","costing_options":{"bicycle":{"bicycle_type":"Road","cycling_speed":17,"use_roads":0.1}}}&api_key=valhalla-xxxxx

This particular query builds a bicycle route to the library at the University of California, Santa Barbara. It includes parameters for riding a Road bicycle at a cycling_speed of 17 kilometers per hour. The use_roads value is a range from 0 to 1, indicating an increasing tolerance for riding with vehicle traffic. By specifying a value closer to 0, though, your query shows a preference for designated bicycle paths, when available. (Note that you would need to substitute your own API key at the end to perform the query.)

To visualize your trip, which is a little over a kilometer in length, you can draw the route line over an OpenCycleMap basemap, which is built from OpenStreetMap data to emphasize cycling. On OpenCycleMap, cycle paths are shown with dashed blue lines, and footpaths are the dashed brown lines.

image title

Here is an overview map of your bike route (shown in solid blue) from the neighborhood to the campus library to the east. A fun fact is that by car, traveling between these same points is three times the bicycle distance because vehicles cannot access such a direct route.

The Valhalla response provides distances and estimated times en route for the entire trip, as well as details for the component legs. Each maneuver has turn-by-turn instructions, including for the bicycle-only roundabouts you will pass through on this trip.

image title

Here is a closer look at some of the maneuvers on your route. The path changes to bicycle-only access when you enter the campus, and then you travel through several roundabouts.

If you choose not to set any bicycle costing options, the route is tuned for road bicycles and the kinds of roads they can access, with a slight preference for using cycleways or roads with bicycle lanes.

Keep in mind that Valhalla bicycle routes do not currently consider elevation factors such as hills and steepness, but this is coming soon.

To get started with Valhalla, sign up for your free API key at https://mapzen.com/developers and check out the documentation.

Credits for this post’s screenshots: OpenCycleMap © Thunderforest, data © OpenStreetMap contributors.