closest way to user location

Hi all, I am playing around a bit with openstreetmap data. What I want to get is the closest “road” (i.e. way with tag ‘highway’ set to certain values) to the users position.
At the moment I use the API to query all Objects in a square around the user and then parse all the way elements, check their tags, check their distance to the user and so on
But that doesn’t sound to elegant to me.
Is there a better solution ? maybe through the API or by installing the openstreetmap data in a local DB somehow to be able to query that directly ?

would be great if someone could point me to the right direction.

Thanks in advance.

After importing data into PostGIS with osm2pgsql these PostGIS recipes should work directly:
As article says, Oracle has special functions SDO_NN and SDO_NN_DISTANCE for this purpose. Importing OSM data is not very simple because shere is no “osm2sdo” tool. Most practical way would probably be to use osm2pgsl firts and then ogr2ogr for the PostGIS → Oracle spatial conversion. However, ogr2ogr does not have Oracle spatial support by default.


thanks for that response - sounds promissing, I’ll look into it

I would think it is possible to achieve what you want using native PostGis functions such as ST_ShortestPath. In general if you assume users live on roads then a buffer of 100metres is likely to encompass any candidate features. So look for ways with appropriate tags within a chosen buffer distance from user location & select MIN(ST_ShortestPath(highway_way,user_node).