How to query the road that I'm driving with Overpass API?

Hi All,

When driving a car, I fetch my current GPS location. After driving 10 more meters, I fetch another one. How to query the most likely road that I’m driving by providing these two points?

An Overpass Turbo example would be welcome :slight_smile:. Thanks

It sounds like what you want to do falls broadly into the category of map matching. There is no convenient list of OSM services that do this on the wiki, but if you search the wiki you will find that the pages of several routers mention it.

I’ll let Mateusz answer about public server usage policies in the comment thread. But you suggested this method to find the most likely road from the two GPS data points:

Fetch a single point, query for roads around. Fetch the second point, query for roads around. Now locally (in my code) find the roads that are common for the two results.

First off, you could easily perform this operation in Overpass, e.g.:

way(around:35,32.7590342,-117.0921544)["highway"] -> .a;
way(around:35,32.7590365,-117.0920478)["highway"] -> .b;
out geom;

But I don’t think that will get you the results you want. There are lots of conditions where that will produce output containing more than one road.

What you really want is to compare the direction of travel between the two GPS points with the direction of the nearby roads. There are some things in Overpass that can measure angles between nodes in a way, but it looks like it would be very hard to use the GPS points to effectively filter results within Overpass and I suspect that you’ll be better off doing that filtering locally.

Even then, I would anticipate that there will be scenarios where the results would necessarily be ambiguous, such as at motorway interchanges or in roundabouts.