Reverse geocodes latitude and longitude coordinates and returns matching
results as a tibble. Latitude values must be in
\(\left[-90, 90 \right]\) and longitudes in
\(\left[-180, 180 \right]\). Use reverse_geo_lite_sf() to return an
sf object instead.
Usage
reverse_geo_lite(
lat,
long,
address = "address",
full_results = FALSE,
return_coords = TRUE,
verbose = FALSE,
nominatim_server = "https://nominatim.openstreetmap.org/",
progressbar = TRUE,
custom_query = list()
)Arguments
- lat
A numeric vector of latitude values in the range \(\left[-90, 90 \right]\).
- long
A numeric vector of longitude values in the range \(\left[-180, 180 \right]\).
- address
A character string specifying the name of the address column in the output. Defaults to
"address".- full_results
A logical value indicating whether to return all available fields from the Nominatim API. If
FALSE, only query metadata, location data and requested address columns are returned.- return_coords
A logical value indicating whether to return the input coordinates with the results.
- verbose
A logical value indicating whether to display detailed messages in the console.
- nominatim_server
A character string specifying the base URL of the Nominatim server. Defaults to
"https://nominatim.openstreetmap.org/".- progressbar
A logical value indicating whether to display a progress bar when processing multiple queries.
- custom_query
A named list of API-specific parameters, for example
list(zoom = 3). See Details.
Value
A tibble with the results that match the query.
Details
See https://nominatim.org/release-docs/latest/api/Reverse/ for additional
parameters to pass to custom_query.
About zooming
Set custom_query = list(zoom = 3) to adjust the output. Selected zoom
levels correspond to these address details:
| zoom | address_detail |
3 | country |
5 | state |
8 | county |
10 | city |
14 | suburb |
16 | major streets |
17 | major and minor streets |
18 | building |
See also
Reverse geocoding functions:
reverse_geo_lite_sf()
Examples
# \donttest{
reverse_geo_lite(lat = 40.75728, long = -73.98586)
#> # A tibble: 1 × 3
#> address lat lon
#> <chr> <dbl> <dbl>
#> 1 West 44th Street, Times Square, Manhattan Community Board 5, Manh… 40.8 -74.0
# Reverse geocode multiple coordinate pairs.
reverse_geo_lite(lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375))
#>
|
| | 0%
|
|========================= | 50%
|
|==================================================| 100%
#> # A tibble: 2 × 3
#> address lat lon
#> <chr> <dbl> <dbl>
#> 1 West 44th Street, Times Square, Manhattan Community Board 5, Man… 40.8 -74.0
#> 2 East End, Waterloo Place, Waterloo Place, Greenside, Broughton, … 56.0 -3.19
# Set the zoom to the country level.
sev <- reverse_geo_lite(
lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375),
custom_query = list(zoom = 0, extratags = TRUE),
verbose = TRUE, full_results = TRUE
)
#>
|
| | 0%
|
|========================= | 50%
|
|==================================================| 100%
dplyr::glimpse(sev)
#> Rows: 2
#> Columns: 52
#> $ address <chr> "United States", "United King…
#> $ lat <dbl> 39.78373, 54.70235
#> $ lon <dbl> -100.445882, -3.276575
#> $ place_id <int> 52172514, 276157440
#> $ licence <chr> "Data © OpenStreetMap contrib…
#> $ osm_type <chr> "relation", "relation"
#> $ osm_id <int> 148838, 62149
#> $ category <chr> "boundary", "boundary"
#> $ type <chr> "administrative", "administra…
#> $ place_rank <int> 4, 4
#> $ importance <dbl> 1.0000000, 0.9388534
#> $ addresstype <chr> "country", "country"
#> $ name <chr> "United States", "United King…
#> $ display_name <chr> "United States", "United King…
#> $ address.country <chr> "United States", "United King…
#> $ address.country_code <chr> "us", "gb"
#> $ extratags.flag <chr> "https://upload.wikimedia.org…
#> $ extratags.sqkm <chr> "9826675", "243610"
#> $ extratags.wikidata <chr> "Q30", "Q145"
#> $ extratags.wikipedia <chr> "en:United States", "en:Unite…
#> $ extratags.check_date <chr> "2024-10-17", NA
#> $ extratags.population <chr> "331449281", "61792000"
#> $ extratags.border_type <chr> "national", NA
#> $ extratags.capital_city <chr> "Washington DC", NA
#> $ extratags.driving_side <chr> "right", "left"
#> $ extratags.linked_place <chr> "country", "country"
#> $ `extratags.contact:website` <chr> "https://www.usa.gov", NA
#> $ `extratags.population:date` <chr> "2020", NA
#> $ `extratags.ISO3166-1:alpha2` <chr> "US", "GB"
#> $ `extratags.ISO3166-1:alpha3` <chr> "USA", "GBR"
#> $ extratags.default_language <chr> "en", "en"
#> $ `extratags.ISO3166-1:numeric` <chr> "840", "826"
#> $ `extratags.alt_short_name:en` <chr> "US;USA", NA
#> $ `extratags.alt_short_name:es` <chr> "EUA", NA
#> $ `extratags.alt_short_name:pl` <chr> "St. Zj.", NA
#> $ extratags.country_code_fips <chr> "US", NA
#> $ `extratags.old_short_name:ru` <chr> "САСШ", NA
#> $ extratags.wikimedia_commons <chr> "Category:United States", "Ca…
#> $ extratags.short_official_name <chr> "U.S.A.", NA
#> $ `extratags.alt_official_name:en` <chr> "The United States of America…
#> $ `extratags.not:official_name:vi` <chr> "Hợp chủng quốc Hoa Kỳ;Hợp ch…
#> $ `extratags.short_official_name:en` <chr> "U.S.A.", NA
#> $ extratags.country_code_iso3166_1_alpha_2 <chr> "US", NA
#> $ extratags.admin_level <chr> "2", "2"
#> $ boundingbox <list> <-14.76084, 71.58895, -180.00…
#> $ `extratags.ref:gss` <chr> NA, "K02000001"
#> $ extratags.currency <chr> NA, "GBP"
#> $ extratags.timezone <chr> NA, "Europe/London"
#> $ extratags.native_name <chr> NA, "United Kingdom of Great …
#> $ `extratags.native_name:da` <chr> NA, "Det Forenede Kongerige S…
#> $ `extratags.native_name:es` <chr> NA, "Reino Unido de Gran Bret…
#> $ `extratags.native_name:vi` <chr> NA, "Vương quốc Liên hiệp Anh…
# }
