NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am trying to develop an application, which finds a route between two points, and displays current speed limits as you drive.

So far I managed to use OSRM API ( ) to get a route geometry (as a list of coordinates) and driving directions (as simple instructions, not correlated with OSM objects). I am also aware, that some ways in OSM provide numeric values of speed limits in their tags. What I don't know is how to cherry-pick the needed ways from Overpass API (ideally without any excessive data) and how to associate my route geometry with proper limits. Or maybe there is an other, more comprehensive tool capable of satisfying my needs?

Thank you in advance for any help!

EDIT: I already received a great answer for my problem, but out of curiosity I would also appreciate a solution which does not involve interfering in OSRM API

asked 25 Apr '14, 23:13

soul123's gravatar image

accept rate: 0%

edited 29 Sep '16, 09:38

nevw's gravatar image


It may be easier to do this by setting up your own instance of OSRM. You can then return the speed limit as part of the turn-by-turn directions, rather than just the road number.

You would typically do this in the Lua profile of your OSRM instance. In way_function, after has been set to the ref/name, add code such as this:

if maxspeed>0 then"|"..maxspeed end

In other words, if there's a maxspeed value for the way, append it to the way name, separated by a | symbol.

You can then parse this value in your JavaScript (or other) client.

permanent link

answered 26 Apr '14, 12:18

Richard's gravatar image

Richard ♦
accept rate: 18%

edited 26 Apr '14, 12:18

Thank you for this answer, it's great and accurate!

(26 Apr '14, 13:22) soul123

How is this solved in the last version of API (Version 5). Let's say if we want to use the default car profile, what exactly should be changed to get the speed limits too? Where exactly should the speed limits appear in the resulting JSON? Thanks

(26 Sep '16, 16:50) pksk88

Hi - sorry to "me too", but I'm also looking for a method to do this in the current API. The car.lua profile files appear to be substantially different from the those in the answers suggested so far. Many thanks.

(02 Mar '17, 14:05) AndyC

Hey! Is there a similar solution for the current version? I really don't know where to put the suggested lines of code. Or respectively how to modify them to either adding the maxspeed attribute to another attribute or creating a new attribute in the output. That would be of great help for me - many thanks in advance.

permanent link

answered 03 Apr '18, 19:12

jandoh's gravatar image

accept rate: 0%


I'm not an expert on the current OSRM API profiles, but it might be worth asking the developers at (you'll need a Github account).

(03 Apr '18, 19:19) Richard ♦

For the current version of API I used this temporary solution, analogous to the above mentioned. Using the car.lua profile you may insert the maxspeed attribute as part of other attributes. This could be done on multiple places. I added the

local maxspeed = parse_maxspeed( way:get_value_by_key("maxspeed") )

on line 430 and then on line 446 changed the code to

result.ref = ref.."|"..maxspeed

This is a very simple way but not really standard. I would like to create a separate JSON attribute for maxspeed in the response of API.

permanent link

answered 29 Sep '16, 08:05

pksk88's gravatar image

accept rate: 0%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 25 Apr '14, 23:13

question was seen: 10,322 times

last updated: 03 Apr '18, 19:19

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum