]> git.openstreetmap.org Git - nominatim.git/blob - docs/api/Reverse.md
add additional stats for search queries
[nominatim.git] / docs / api / Reverse.md
1 # Reverse Geocoding
2
3 Reverse geocoding generates an address from a coordinate given as
4 latitude and longitude.
5
6 ## How it works
7
8 The reverse geocoding API does not exactly compute the address for the
9 coordinate it receives. It works by finding the closest suitable OSM object
10 and returning its address information. This may occasionally lead to
11 unexpected results.
12
13 First of all, Nominatim only includes OSM objects in
14 its index that are suitable for searching. Small, unnamed paths for example
15 are missing from the database and can therefore not be used for reverse
16 geocoding either.
17
18 The other issue to be aware of is that the closest OSM object may not always
19 have a similar enough address to the coordinate you were requesting. For
20 example, in dense city areas it may belong to a completely different street.
21
22 ## Endpoint
23
24 The main format of the reverse API is
25
26 ```
27 https://nominatim.openstreetmap.org/reverse?lat=<value>&lon=<value>&<params>
28 ```
29
30 where `lat` and `lon` are latitude and longitude of a coordinate in WGS84
31 projection. The API returns exactly one result or an error when the coordinate
32 is in an area with no OSM data coverage.
33
34
35 !!! tip
36     The reverse API allows a lookup of object by coordinate. If you want
37     to look up an object by ID, use the [Address Lookup API](Lookup.md) instead.
38
39 !!! danger "Deprecation warning"
40     The API can also be used with the URL
41     `https://nominatim.openstreetmap.org/reverse.php`. This is now deprecated
42     and will be removed in future versions.
43
44
45 ## Parameters
46
47 This section lists additional parameters to further influence the output.
48
49 ### Output format
50
51 | Parameter | Value | Default |
52 |-----------| ----- | ------- |
53 | format    | one of: `xml`, `json`, `jsonv2`, `geojson`, `geocodejson` | `xml` |
54
55 See [Place Output Formats](Output.md) for details on each format.
56
57
58 | Parameter | Value | Default |
59 |-----------| ----- | ------- |
60 | json_callback | function name | _unset_ |
61
62 When given, then JSON output will be wrapped in a callback function with
63 the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
64 information.
65
66 Only has an effect for JSON output formats.
67
68
69 ### Output details
70
71 | Parameter | Value | Default |
72 |-----------| ----- | ------- |
73 | addressdetails | 0 or 1 | 1 |
74
75 When set to 1, include a breakdown of the address into elements.
76 The exact content of the address breakdown depends on the output format.
77
78 !!! tip
79     If you are interested in a stable classification of address categories
80     (suburb, city, state, etc), have a look at the `geocodejson` format.
81     All other formats return classifications according to OSM tagging.
82     There is a much larger set of categories and they are not always consistent,
83     which makes them very hard to work with.
84
85
86 | Parameter | Value | Default |
87 |-----------| ----- | ------- |
88 | extratags | 0 or 1 | 0 |
89
90 When set to 1, the response include any additional information in the result
91 that is available in the database, e.g. wikipedia link, opening hours.
92
93
94 | Parameter | Value | Default |
95 |-----------| ----- | ------- |
96 | namedetails | 0 or 1 | 0 |
97
98 When set to 1, include a full list of names for the result. These may include
99 language variants, older names, references and brand.
100
101 | Parameter | Value | Default |
102 |-----------| ----- | ------- |
103 | entrances | 0 or 1 | 0 |
104
105 When set to 1, include the tagged entrances in the result.
106
107
108 ### Language of results
109
110 | Parameter | Value | Default |
111 |-----------| ----- | ------- |
112 | accept-language | browser language string | content of "Accept-Language" HTTP header |
113
114 Preferred language order for showing search results. This may either be
115 a simple comma-separated list of language codes or have the same format
116 as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
117
118 !!! tip
119     First-time users of Nominatim tend to be confused that they get different
120     results when using Nominatim in the browser versus in a command-line tool
121     like wget or curl. The command-line tools
122     usually don't send any Accept-Language header, prompting Nominatim
123     to show results in the local language. Browsers on the contrary always
124     send the currently chosen browser language.
125
126
127 ### Result restriction
128
129 | Parameter | Value | Default |
130 |-----------| ----- | ------- |
131 | zoom      | 0-18  | 18      |
132
133 Level of detail required for the address. This is a number that
134 corresponds roughly to the zoom level used in XYZ tile sources in frameworks
135 like Leaflet.js, Openlayers etc.
136 In terms of address details the zoom levels are as follows:
137
138  zoom | address detail
139  -----|---------------
140   3   | country
141   5   | state
142   8   | county
143   10  | city
144   12  | town / borough
145   13  | village / suburb
146   14  | neighbourhood
147   15  | any settlement
148   16  | major streets
149   17  | major and minor streets
150   18  | building
151
152
153 | Parameter | Value | Default |
154 |-----------| ----- | ------- |
155 | layer     | comma-separated list of: `address`, `poi`, `railway`, `natural`, `manmade` | _unset_ (no restriction) |
156
157 The layer filter allows to select places by themes.
158
159 The `address` layer contains all places that make up an address:
160 address points with house numbers, streets, inhabited places (suburbs, villages,
161 cities, states etc.) and administrative boundaries.
162
163 The `poi` layer selects all point of interest. This includes classic points
164 of interest like restaurants, shops, hotels but also less obvious features
165 like recycling bins, guideposts or benches.
166
167 The `railway` layer includes railway infrastructure like tracks.
168 Note that in Nominatim's standard configuration, only very few railway
169 features are imported into the database.
170
171 The `natural` layer collects features like rivers, lakes and mountains while
172 the `manmade` layer functions as a catch-all for features not covered by the
173 other layers.
174
175
176 ### Polygon output
177
178 | Parameter | Value  | Default |
179 |-----------| -----  | ------- |
180 | polygon_geojson | 0 or 1 | 0 |
181 | polygon_kml     | 0 or 1 | 0 |
182 | polygon_svg     | 0 or 1 | 0 |
183 | polygon_text    | 0 or 1 | 0 |
184
185 Add the full geometry of the place to the result output. Output formats
186 in GeoJSON, KML, SVG or WKT are supported. Only one of these
187 options can be used at a time.
188
189 | Parameter | Value  | Default |
190 |-----------| -----  | ------- |
191 | polygon_threshold | floating-point number | 0.0 |
192
193 When one of the polygon_* outputs is chosen, return a simplified version
194 of the output geometry. The parameter describes the
195 tolerance in degrees with which the geometry may differ from the original
196 geometry. Topology is preserved in the geometry.
197
198
199 ### Other
200
201 | Parameter | Value  | Default |
202 |-----------| -----  | ------- |
203 | email     | valid email address | _unset_ |
204
205 If you are making large numbers of request please include an appropriate email
206 address to identify your requests. See Nominatim's
207 [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
208
209
210 | Parameter | Value  | Default |
211 |-----------| -----  | ------- |
212 | debug     | 0 or 1 | 0       |
213
214 Output assorted developer debug information. Data on internals of Nominatim's
215 "search loop" logic, and SQL queries. The output is HTML format.
216 This overrides the specified machine readable format.
217
218
219 ## Examples
220
221 * [https://nominatim.openstreetmap.org/reverse?format=xml&lat=52.5487429714954&lon=-1.81602098644987&zoom=18&addressdetails=1](https://nominatim.openstreetmap.org/reverse?format=xml&lat=52.5487429714954&lon=-1.81602098644987&zoom=18&addressdetails=1)
222
223 ```xml
224   <reversegeocode timestamp="Fri, 06 Nov 09 16:33:54 +0000" querystring="...">
225     <result place_id="1620612" osm_type="node" osm_id="452010817">
226       135, Pilkington Avenue, Wylde Green, City of Birmingham, West Midlands (county), B72, United Kingdom
227     </result>
228     <addressparts>
229       <house_number>135</house_number>
230       <road>Pilkington Avenue</road>
231       <village>Wylde Green</village>
232       <town>Sutton Coldfield</town>
233       <city>City of Birmingham</city>
234       <county>West Midlands (county)</county>
235       <postcode>B72</postcode>
236       <country>United Kingdom</country>
237       <country_code>gb</country_code>
238     </addressparts>
239   </reversegeocode>
240 ```
241
242 ##### Example with `format=jsonv2`
243
244 * [https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=-34.44076&lon=-58.70521](https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=-34.44076&lon=-58.70521)
245
246 ```json
247 {
248   "place_id":"134140761",
249   "licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/www.openstreetmap.org\/copyright",
250   "osm_type":"way",
251   "osm_id":"280940520",
252   "lat":"-34.4391708",
253   "lon":"-58.7064573",
254   "place_rank":"26",
255   "category":"highway",
256   "type":"motorway",
257   "importance":"0.1",
258   "addresstype":"road",
259   "display_name":"Autopista Pedro Eugenio Aramburu, El Triángulo, Partido de Malvinas Argentinas, Buenos Aires, 1.619, Argentina",
260   "name":"Autopista Pedro Eugenio Aramburu",
261   "address":{
262     "road":"Autopista Pedro Eugenio Aramburu",
263     "village":"El Triángulo",
264     "state_district":"Partido de Malvinas Argentinas",
265     "state":"Buenos Aires",
266     "postcode":"1.619",
267     "country":"Argentina",
268     "country_code":"ar"
269   },
270   "boundingbox":["-34.44159","-34.4370994","-58.7086067","-58.7044712"]
271 }
272 ```
273
274 ##### Example with `format=geojson`
275
276 * [https://nominatim.openstreetmap.org/reverse?format=geojson&lat=44.50155&lon=11.33989](https://nominatim.openstreetmap.org/reverse?format=geojson&lat=44.50155&lon=11.33989)
277
278 ```json
279 {
280   "type": "FeatureCollection",
281   "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
282   "features": [
283     {
284       "type": "Feature",
285       "properties": {
286         "place_id": "18512203",
287         "osm_type": "node",
288         "osm_id": "1704756187",
289         "place_rank": "30",
290         "category": "place",
291         "type": "house",
292         "importance": "0",
293         "addresstype": "place",
294         "name": null,
295         "display_name": "71, Via Guglielmo Marconi, Saragozza-Porto, Bologna, BO, Emilia-Romagna, 40122, Italy",
296         "address": {
297           "house_number": "71",
298           "road": "Via Guglielmo Marconi",
299           "suburb": "Saragozza-Porto",
300           "city": "Bologna",
301           "county": "BO",
302           "state": "Emilia-Romagna",
303           "postcode": "40122",
304           "country": "Italy",
305           "country_code": "it"
306         }
307       },
308       "bbox": [
309         11.3397676,
310         44.5014307,
311         11.3399676,
312         44.5016307
313       ],
314       "geometry": {
315         "type": "Point",
316         "coordinates": [
317           11.3398676,
318           44.5015307
319         ]
320       }
321     }
322   ]
323 }
324 ```
325
326 ##### Example with `format=geocodejson`
327
328 [https://nominatim.openstreetmap.org/reverse?format=geocodejson&lat=60.2299&lon=11.1663](https://nominatim.openstreetmap.org/reverse?format=geocodejson&lat=60.2299&lon=11.1663)
329
330 ```json
331 {
332   "type": "FeatureCollection",
333   "geocoding": {
334     "version": "0.1.0",
335     "attribution": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
336     "licence": "ODbL",
337     "query": "60.229917843587,11.16630979382"
338   },
339   "features": {
340     "type": "Feature",
341     "properties": {
342       "geocoding": {
343         "place_id": "42700574",
344         "osm_type": "node",
345         "osm_id": "3110596255",
346         "type": "house",
347         "accuracy": 0,
348         "label": "1, Løvenbergvegen, Mogreina, Ullensaker, Akershus, 2054, Norway",
349         "name": null,
350         "housenumber": "1",
351         "street": "Løvenbergvegen",
352         "postcode": "2054",
353         "county": "Akershus",
354         "country": "Norway",
355         "admin": {
356           "level7": "Ullensaker",
357           "level4": "Akershus",
358           "level2": "Norway"
359         }
360       }
361     },
362     "geometry": {
363       "type": "Point",
364       "coordinates": [
365         11.1658572,
366         60.2301296
367       ]
368     }
369   }
370 }
371 ```
372