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