Reverse geocodes geographic coordinates (latitude and longitude) given as numeric values.
Latitude and longitude inputs are limited to possible values. Latitudes must be between -90 and 90 and
longitudes must be between -180 and 180. Invalid values will not be sent to the geocoding service.
The reverse_geocode function utilizes this function on coordinates contained in dataframes.
See example usage in vignette("tidygeocoder")
.
Refer to api_parameter_reference, min_time_reference, and batch_limit_reference for more details on geocoding service parameters and usage.
This function uses the get_api_query, query_api, and extract_reverse_results functions to create, execute, and parse geocoder API queries.
reverse_geo(
lat,
long,
method = "osm",
address = "address",
limit = 1,
full_results = FALSE,
mode = "",
unique_only = FALSE,
return_coords = TRUE,
min_time = NULL,
progress_bar = show_progress_bar(),
quiet = getOption("tidygeocoder.quiet", FALSE),
api_url = NULL,
timeout = 20,
flatten = TRUE,
batch_limit = NULL,
verbose = getOption("tidygeocoder.verbose", FALSE),
no_query = FALSE,
custom_query = list(),
api_options = list()
)
latitude values (input data)
longitude values (input data)
the geocoding service to be used. API keys are loaded from environmental variables. Run usethis::edit_r_environ()
to open your .Renviron file and add an API key as an environmental variable. For example, add the line GEOCODIO_API_KEY="YourAPIKeyHere"
"osm"
: Nominatim.
"arcgis"
: ArcGIS.
"geocodio"
: Geocodio. Geographic coverage is limited to the United States and Canada. Batch geocoding is supported. Store an API key in the environmental variable "GEOCODIO_API_KEY"
.
"iq"
: Location IQ. Store an API key in the environmental variable "LOCATIONIQ_API_KEY"
.
"google"
: Google. Store an API key in the environmental variable "GOOGLEGEOCODE_API_KEY"
.
"opencage"
: OpenCage. Store an API key in the environmental variable "OPENCAGE_KEY"
.
"mapbox"
: Mapbox. Store an API key in the environmental variable "MAPBOX_API_KEY"
.
"here"
: HERE. Batch geocoding is supported, but must be explicitly called with mode = "batch"
. Store an API key in the environmental variable "HERE_API_KEY"
.
"tomtom"
: TomTom. Batch geocoding is supported. Store an API key in the environmental variable "TOMTOM_API_KEY"
.
"mapquest"
: MapQuest. Batch geocoding is supported. Store an API key in the environmental variable "MAPQUEST_API_KEY"
.
"bing"
: Bing. Batch geocoding is supported, but must be explicitly called with mode = "batch"
. Store an API key in the environmental variable "BINGMAPS_API_KEY"
.
"geoapify"
: Geoapify. Store an API key in the environmental variable "GEOAPIFY_KEY"
.
name of the address column (in the output data)
maximum number of results to return per input coordinate. For many geocoding services the maximum value of the limit parameter is 100. Pass limit = NULL
to use the default limit
value of the selected geocoding service. For batch geocoding, limit must be set to 1 (default) if return_coords = TRUE
. Refer to api_parameter_reference for more details.
returns all available data from the geocoding service if TRUE. If FALSE (default) then only a single address column is returned from the geocoding service.
set to 'batch' to force batch geocoding or 'single' to force single coordinategeocoding (one coordinate per query). If not specified then batch geocoding will be used if available (given method selected) when multiple coordinates are provided; otherwise single address geocoding will be used. For the "here" and "bing" methods the batch mode should be explicitly specified with mode = 'batch'
.
only return results for unique inputs if TRUE
return input coordinates with results if TRUE. Note that
most services return the input coordinates with full_results = TRUE
and setting
return_coords
to FALSE does not prevent this.
minimum amount of time for a query to take (in seconds). If NULL then min_time will be set to the default value specified in min_time_reference.
if TRUE then a progress bar will be displayed
for single input geocoding (1 input per query). By default the progress bar
will not be shown for code executed when knitting R Markdown files or code within
an RStudio notebook chunk. Can be set permanently with options(tidygeocoder.progress_bar = FALSE)
.
if TRUE then console messages that are displayed by default
regarding queries will be suppressed. FALSE is default.
Can be set permanently with options(tidygeocoder.quiet = TRUE)
.
custom API URL. If specified, the default API URL will be overridden. This parameter can be used to specify a local Nominatim server, for instance.
query timeout (in minutes)
if TRUE (default) then any nested dataframes in results are flattened if possible. Note that in some cases results are flattened regardless such as for Geocodio batch geocoding.
limit to the number of coordinates in a batch geocoding query.Defaults to the value in batch_limit_reference if not specified.
if TRUE then detailed logs are output to the console. FALSE is default. Can be set
permanently with options(tidygeocoder.verbose = TRUE)
if TRUE then no queries are sent to the geocoding service and verbose is set to TRUE. Used for testing.
API-specific parameters to be used, passed as a named list
(ex. list(extratags = 1)
.
a named list of parameters specific to individual services.
(ex. list(geocodio_v = 1.6, geocodio_hipaa = TRUE)
). Each parameter begins
with the name of the method
(service) it applies to. The possible parameters
are shown below with their default values.
census_return_type
(default: locations): set to "geographies"
to return
additional geography columns. Make sure to use full_results = TRUE
if using
the "geographies" setting.
iq_region
(default: "us"): set to "eu" to use the European Union API endpoint
geocodio_v
(default: 1.7): the version number of the Geocodio API to be used
geocodio_hipaa
(default: FALSE): set to TRUE
to use the HIPAA compliant
Geocodio API endpoint
mapbox_permanent
(default: FALSE): set to TRUE
to use the mapbox.places-permanent
endpoint. Note that this option should be used only if you have applied for a permanent
account. Unsuccessful requests made by an account that does not have access to the
endpoint may be billable.
mapquest_open
(default: FALSE): set to TRUE
to use the Open Geocoding endpoint which
relies solely on OpenStreetMap data
here_request_id
: this parameter would return a previous HERE batch job,
identified by its RequestID. The RequestID of a batch job is displayed
when verbose
is TRUE. Note that this option would ignore the
current address
parameter on the request, so the return_addresses
or return_coords
parameters need to be FALSE.
tibble (dataframe)
# \donttest{
options(tidygeocoder.progress_bar = FALSE)
reverse_geo(lat = 38.895865, long = -77.0307713, method = "osm")
#> Passing 1 coordinate to the Nominatim single coordinate geocoder
#> Query completed in: 1 seconds
#> # A tibble: 1 × 3
#> lat long address
#> <dbl> <dbl> <chr>
#> 1 38.9 -77.0 L’Enfant's plan, Pennsylvania Avenue, Washington, District of Col…
reverse_geo(
lat = c(38.895865, 43.6534817, 300),
long = c(-77.0307713, -79.3839347, 600),
method = "osm", full_results = TRUE
)
#> Passing 2 coordinates to the Nominatim single coordinate geocoder
#> Query completed in: 2 seconds
#> # A tibble: 3 × 23
#> lat long address place…¹ licence osm_t…² osm_id osm_lat osm_lon tourism
#> <dbl> <dbl> <chr> <int> <chr> <chr> <int> <chr> <chr> <chr>
#> 1 38.9 -77.0 L’Enfant'… 2.75e8 Data ©… way 9.00e8 38.895… -77.03… L’Enfa…
#> 2 43.7 -79.4 Toronto C… 1.53e8 Data ©… way 1.99e8 43.653… -79.38… NA
#> 3 NA NA NA NA NA NA NA NA NA NA
#> # … with 13 more variables: road <chr>, city <chr>, state <chr>,
#> # `ISO3166-2-lvl4` <chr>, postcode <chr>, country <chr>, country_code <chr>,
#> # boundingbox <list>, amenity <chr>, house_number <chr>, neighbourhood <chr>,
#> # quarter <chr>, state_district <chr>, and abbreviated variable names
#> # ¹place_id, ²osm_type
# }