Skip to contents

Geocodes addresses given as character values and returns the tibble associated with the query. See geo_lite_sf() for retrieving the data as an sf object.

Corresponds to the free-form query search described in the API endpoint.

Usage

geo_lite(
  address,
  lat = "lat",
  long = "lon",
  limit = 1,
  full_results = FALSE,
  return_addresses = TRUE,
  verbose = FALSE,
  nominatim_server = "https://nominatim.openstreetmap.org/",
  progressbar = TRUE,
  custom_query = list()
)

Arguments

address

character with a single-line address, for example "1600 Pennsylvania Ave NW, Washington", or a vector of addresses (c("Madrid", "Barcelona")).

lat

Latitude column name in the output data (default "lat").

long

Longitude column name in the output data (default "long").

limit

Maximum number of results to return per input address. Note that each query returns a maximum of 50 results.

full_results

Return all available data from the Nominatim API. If FALSE (default), only latitude, longitude and address columns are returned. See also return_addresses.

return_addresses

Return input addresses with results if TRUE.

verbose

If TRUE, detailed logs are output to the console.

nominatim_server

URL of the Nominatim server to use. Defaults to "https://nominatim.openstreetmap.org/".

progressbar

Logical. If TRUE displays a progress bar to indicate the progress of the function.

custom_query

Named list with API-specific parameters, for example list(countrycodes = "US"). See Details.

Value

A tibble with the results that match the query.

Details

See https://nominatim.org/release-docs/latest/api/Search/ for additional parameters to be passed to custom_query.

Examples

# \donttest{
geo_lite("Madrid, Spain")
#> # A tibble: 1 × 4
#>   query           lat   lon address                            
#>   <chr>         <dbl> <dbl> <chr>                              
#> 1 Madrid, Spain  40.4 -3.70 Madrid, Comunidad de Madrid, España

# Several addresses
geo_lite(c("Madrid", "Barcelona"))
#> 
  |                                                        
  |                                                  |   0%
  |                                                        
  |=========================                         |  50%
  |                                                        
  |==================================================| 100%
#> # A tibble: 2 × 4
#>   query       lat   lon address                                            
#>   <chr>     <dbl> <dbl> <chr>                                              
#> 1 Madrid     40.4 -3.70 Madrid, Comunidad de Madrid, España                
#> 2 Barcelona  41.4  2.18 Barcelona, Barcelonès, Barcelona, Catalunya, España

# With options: restrict search to the United States
geo_lite(c("Madrid", "Barcelona"),
  custom_query = list(countrycodes = "US"),
  full_results = TRUE
)
#> 
  |                                                        
  |                                                  |   0%
  |                                                        
  |=========================                         |  50%
  |                                                        
  |==================================================| 100%
#> # A tibble: 2 × 24
#>   query       lat   lon address  place_id licence osm_type osm_id category type 
#>   <chr>     <dbl> <dbl> <chr>       <int> <chr>   <chr>     <int> <chr>    <chr>
#> 1 Madrid     41.9 -93.8 Madrid,…   3.73e8 Data ©… relation 1.29e5 boundary admi…
#> 2 Barcelona  42.3 -79.6 Barcelo…   3.51e8 Data ©… node     1.58e8 place    haml…
#> # ℹ 14 more variables: place_rank <int>, importance <dbl>, addresstype <chr>,
#> #   name <chr>, display_name <chr>, address.town <chr>, address.county <chr>,
#> #   address.state <chr>, `address.ISO3166-2-lvl4` <chr>, address.country <chr>,
#> #   address.country_code <chr>, boundingbox <list>, address.hamlet <chr>,
#> #   address.postcode <chr>
# }