Search code examples
javascriptopenstreetmapoverpass-api

Get current road speed limit


I am trying to develop a Javascript program which gets the current speed limit of the current road. I have tried using using the Overpass API, but that only returns an empty XML file:

/interpreter?node(around:10, 40.7127, 74.0059)[maxspeed];out;

I haven't implemented this into my code yet, testing it on Firefox.

Why is the XML file empty, and are there any other free online resources which can be used to get the speed limit of a road at coordinates x,y?

Note: I would prefer if it supported speed limits in the UK


Solution

  • Two reasons your query returns an empty result:

    • You are querying in a very sparsely mapped region
    • You are querying for nodes instead of ways

    Try this query instead:

    way
      (around:70, 51.0483, 13.7495)
      [maxspeed];
    (._;>;);
    out;
    

    See the result on overpass turbo.