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 ( http://project-osrm.org/ ) 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 |
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 way.name has been set to the ref/name, add code such as this:
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. answered 26 Apr '14, 12:18 Richard ♦ 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
|
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
on line 430 and then on line 446 changed the code to
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. answered 29 Sep '16, 08:05 pksk88 |
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. answered 03 Apr '18, 19:12 jandoh 1
I'm not an expert on the current OSRM API profiles, but it might be worth asking the developers at https://github.com/Project-OSRM/osrm-backend/issues (you'll need a Github account).
(03 Apr '18, 19:19)
Richard ♦
|