[GIS] Get Road name from coordinates to be used in Overpass api

openstreetmapoverpass-api

I have following Overpass api quer that takes the name of the road and give back entire road coordinates

http://overpass-api.de/api/interpreter?data=[out:json][timeout:25];(node["name"="%@"];way["name"="%@"];relation["name"="%@"];);(node["ref"="%@"];way["ref"="%@"];relation["ref"="%@"];);out body;>;out skel qt;

I am using following query to get the name of road from coordinates

http://nominatim.openstreetmap.org/reverse?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1


 NSDictionary *dict = [response JSONValue];
 //NSString *placeId = [dict objectForKey:@"place_id"];
 //NSString *osmId   = [dict objectForKey:@"osm_id"];

 NSDictionary *roadDict = [dict objectForKey:@"address"];
 NSString *roadName = [roadDict objectForKey:@"road"];

Currently i have an example of Roadname @"John F Foran Freeway" using coordinates

[[CLLocation alloc] initWithLatitude:37.731267 longitude:-122.423580];

When i use this roadname in my overpass api. I get no results. Why its not detecting the road? Sometimes on few roadnames it work but mostly it don't recognize the road name. What is wrong?

http://overpass-api.de/api/interpreter?data=[out:json][timeout:25];(node["name"="John F Foran Freeway"];way["name"="John F Foran Freeway"];relation["name"="John F Foran Freeway"];);(node["ref"="John F Foran Freeway"];way["ref"="John F Foran Freeway"];relation["ref"="John F Foran Freeway"];);out body;>;out skel qt;

Best Answer

You didn't tell us how name and ref are related in your query but in case you want to get all objects with a specific name AND ref value then try this query:

[out:json]
[timeout:25]
;
(
  node
    ["name"="John F Foran Freeway"]
    ["ref"="I 280"];
  way
    ["name"="John F Foran Freeway"]
    ["ref"="I 280"];
  relation
    ["name"="John F Foran Freeway"]
    ["ref"="I 280"];
);
out body;
>;
out skel qt;

You can view the result on overpass turbo.

If you want to get all roads with a specific name OR ref value then use this query instead:

[out:json]
[timeout:25]
;
(
  node["name"="John F Foran Freeway"];
  way["name"="John F Foran Freeway"];
  relation["name"="John F Foran Freeway"];
  node["ref"="I 280"];
  way["ref"="I 280"];
  relation["ref"="I 280"];
);
out body;
>;
out skel qt;

You can view the result on overpass turbo.

But it seems like your reverse geocoding step is unnecessary if you just want to retrieve roads in your current location. Instead of specifying the name of the road just query for all ways with the highway tag in a given bounding box:

[out:json]
[timeout:25]
;
(
  way
    ["highway"]
    (37.79396544487583,-122.3838801383972,37.80200543920775,-122.37458467483522);
);
out body;
>;
out skel qt;

Again, you can view the result on overpass turbo.

See the Overpass API language guide for more information.