How to find nearest road(API)

Hi people!

I am a java developer and I need to quickly solve the problem. I need to find the nearest road(highway) of the user location(GPS point). This is possible with the OpenStreetMap? I’m tried to read API docs, but have not found anything similar.

Thanks.

Of course that’s possible with OSM-Data. The API-Documentation you propably read (this one) is about the API to edit the OSM-Database. You are looking for other services which use OSM-Data to provide an API (like Nominatim) or some library to do this with (offline) OSM-Data in your application.

Thank you!

I understood that I need to write a query, but it does not work.

  <query type="node">
    <has-kv k="highway" v="road"/>    
    <around lat="47.992822" lon="37.80517" radius="1000.0"/>
  </query>
  <print/>

Can you help me?

What API are you using? OverpassAPI?

Yes, I am use http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide for construct query.

This looks like querying for a NODE which has highway=road … that will fail!

Because you have to look for WAYS … and a tag with the key “highway” can have different values, not only “road”

Read much at the OSM wiki, especially at http://wiki.openstreetmap.org/wiki/Elements and http://wiki.openstreetmap.org/wiki/Key:highway

Success?

I would like to suggest this one:

(
  way
  [highway~"^(primary|secondary|tertiary|residential)$"]
  [name];
  (around:100,47.9928,37.8052)
>;);out;

This query in action: http://overpass-turbo.eu/s/19s.

As already mentioned, roads are represented by ways in osm. Roads useful for cars are tagged with highway and one of the values “primary”, “secondary”, “tertiary”, “residential”, and so other values probably not applicable to your region. If you would like to include also footways, please add “pedestrian” to the list.

I’ve added a conditional “[name]” to restrict the result to ways that have a name. This excludes unnamed by-lanes, serviceways, footways and so on. It makes sense when you would like to do something with the name of the road afterwards. Drop this condition if you want also unnamed streets.

The “around” finally has got a smaller radius. It is fine to ask again for the same coordinate with bigger radius if you find nothing, but asking for a whole kilometer in advance will in a city center deliver several metabytes of data. There is unfortunately no “just one element” feature yet, so asking again if the result was empty is the best approximation to this.

Thank you very much!

Maybe somebody knows the java library for this task?

If you just need the name and the geometry you can use GraphHopper for this

Update
Ups, sorry for bringing this again up I was just browsing and didn’t recognize its that old - feel free to delete this message