How to get the speed limit of a road using OpenStreetMaps?

Nicknackd :

Im trying to get the speed limit in a specified road using coordinates, I have tried using OpenStreetMaps but I am very new to this API requesting thing, how would you go about requesting info to the API in java? thanks.

Michael :

Roads in OSM are part of the broader category called 'ways'. For example, to find the max speed of the M25 around London you would query a HTTP GET on

/api/0.6/way/27731013

The response is

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.8.1 (12076 thorn-01.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
 <way id="27731013" visible="true" version="17" changeset="69008803" timestamp="2019-04-08T14:10:29Z" user="ika-chan! UK-USA" uid="1016290">
  <nd ref="210993597"/>
  <nd ref="6390949913"/>
  <nd ref="204492"/>
  <nd ref="12086420"/>
  <nd ref="6390949910"/>
  <nd ref="204490"/>
  <nd ref="6390949967"/>
  <nd ref="6390949908"/>
  <nd ref="669805479"/>
  <tag k="active_traffic_management" v="yes"/>
  <tag k="bicycle" v="no"/>
  <tag k="carriageway_ref" v="A"/>
  <tag k="description" v="London Orbital Motorway"/>
  <tag k="foot" v="no"/>
  <tag k="highway" v="motorway"/>
  <tag k="highways_england:area" v="DBFO5"/>
  <tag k="horse" v="no"/>
  <tag k="int_ref" v="E 15;E 30"/>
  <tag k="lanes" v="4"/>
  <tag k="lit" v="yes"/>
  <tag k="maxspeed" v="70 mph"/>
  <tag k="maxspeed:variable" v="peak_traffic"/>
  <tag k="motor_vehicle" v="designated"/>
  <tag k="oneway" v="yes"/>
  <tag k="operator" v="Highways England"/>
  <tag k="ref" v="M25"/>
  <tag k="source:maxspeed" v="UK:motorway"/>
  <tag k="surface" v="asphalt"/>
 </way>
</osm>

The max speed is

<tag k="maxspeed" v="70 mph"/>

This may not always be present. As per this post on the OSM forums

Data in OSM is patchy, and only ~7% of highways in OSM have a maxspeed tag. But many (all?) countries have default speed limits based on the road classification, and you can deduce this from the highway tag value (or the ref), so just because the maxspeed tag is missing doesn't mean that you cannot deduce the speed limit. However this requires you to know the speed limits (or road classifications) for the country/ies you're interested in.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=334363&siteId=1