I need to do the following task: to retrieve the road type (highway, bridge, track, pedestrian and others) by coordinates, query a remote service (via HTTP).

I'm looking at the different major solutions available on the web (OpenStreetMap, Google Maps, Bing Maps, HERE Maps, Apple Maps), trying to compare them to better identify their limitations, but I need help completing this list.

At the moment, I just scouted OpenStreetMap service: using OverpassAPI or a 2-queries method: using Nominatim + XAPI

What about the other services?

Google Maps: ??? Bing Maps: ??? HERE Maps: ??? Apple Maps: ???

  • So you are looking for Reverse Geocoding? Most of the API's you list support it but for addresses not roads
    – Mapperz
    Apr 22 '15 at 15:42
  • Google Maps json response maps.google.com/maps/api/geocode/…
    – Mapperz
    Apr 22 '15 at 15:47
  • Yes, I'm looking for reverse geocoding. What you pasted here is the link to the location (address) retrieved by the service by coordinates. Instead, I need the road type information (e.g.: the road at [23.0043673, 72.5411868999996] is a dirt road). For Google Maps, I found this link which says version 2 is NOT capable to get the information about the road type. Is it still impossible to get in current version 3?
    – ForzaZanzi
    Apr 23 '15 at 6:56

It probably depend on what you want to do with these informations and on the number of points on which you want apply this.

1) If you have not many points you can maybe try to do this with the overpass API. Trying to get the closest road around your pair of coordinates. It might look like this :

out geom;

You can take a small radius (like 1) and increasing it if you dont have result. Depending on what you want to do with your data, but this should provide you the infos you want (if you dont need geometry you can use out; instead of out geom;). It might be useful to have some basics in a scripting language to make the queries (increasing the radius if no result, etc.) and to process the data retrieved (or/and you can use a library like overpy which provide python bindings for the overpass API).

2) If you have many points, maybe you can have a look on the photon project, it's a geocoder based on elasticsearch and nominatim. I think you can make a reverse geocoding request and get the road type (at least the value for the key "highway" and the corresping osm id) with a local instance of this geocoder. The reverse API is not really documented on the main page but here.

Hope that it can help you.


It can be done in two steps:

  1. Make a request to: http://osrm.mapzen.com/car/nearest?loc=lat,lon
  2. Make a request to: http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&lat=lat&lon=lon&addressdetails=1&zoom=18



Returns: [-25.462494,-49.224087] then


  • This answer sounds fantastic. Unfortunately the links do not work anymore...
    – Martin
    Feb 5 '20 at 15:48

My solution requires running your own instance of OSRM, but once you have that, you can apply a patch such as this to profiles/lib/way_handlers.lua to hide the road-type in the name (I chose to hide it there by encoding it as json). Then, when you request http://localhost:5000/car/nearest?loc=lat,lon, you will get the road "name" in the response, from which you can extract the type. If you're only interested in the type, you could just skip the json encoding and replace the name with the road type.


Here is a simple solution using the latest update of the OSMnx package. I followed the implementation from https://github.com/gboeing/osmnx/pull/231/files

# pip install rtree, osmnx 
import osmnx as ox
lat = 50
lon = 10

# Download road network as a so-called Graph object
# The network will be centered at your coordinate
# and includes all nodes in the vicinity of 2 km
G = ox.graph_from_point((lat,lon), distance=2000, network_type='all')
# plot if you wish

# Convert Graph to graph data frame
gdf = ox.graph_to_gdfs(G, nodes=False, fill_edge_geometry=True)
# extract roads and some properties
roads = gdf[["geometry", "u", "v","ref","name","highway","lanes"]].values.tolist()
# calculate and attach distance
roads_with_distances = [(road, ox.Point(tuple(reversed((lat,lon)))).distance(road[0])) for road in roads]

# sort by distance
roads_with_distances = sorted(roads_with_distances, key=lambda x: x[1])
# Select closest road
closest_road = roads_with_distances[0]

Now, closest_road[1] contains the distance between your coordinate and the road (in case you want to do further checks), and closest_road[0][5] containts the road type:

> closest_road[0][5]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.