The get_api_query function can create queries for this function to execute.

query_api(
  api_url,
  query_parameters,
  mode = "single",
  batch_file = NULL,
  input_list = NULL,
  content_encoding = "UTF-8",
  timeout = 20,
  method = ""
)

Arguments

api_url

Base URL of the API. query parameters are appended to this

query_parameters

api query parameters in the form of a named list

mode

determines the type of query to execute

  • "single": geocode a single input (all methods)

  • "list": batch geocode a list of inputs (ex. geocodio)

  • "file": batch geocode a file of inputs (ex. census)

batch_file

a csv file of input data to upload (for mode = 'file')

input_list

a list of input data (for mode = 'list')

content_encoding

Encoding to be used for parsing content

timeout

timeout in minutes

method

if 'mapquest' or 'arcgis' then the query status code is changed appropriately

Value

a named list containing the response content (content) and the HTTP request status (status)

Examples

# \donttest{
raw1 <- query_api(
  "http://nominatim.openstreetmap.org/search",
  get_api_query("osm", list(address = "Hanoi, Vietnam"))
)

raw1$status
#> [1] 200

extract_results("osm", jsonlite::fromJSON(raw1$content))
#>        lat     lon  place_id
#> 1 21.02833 105.854 221315765
#>                                                                 licence
#> 1 Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright
#>   osm_type  osm_id    class           type place_rank importance addresstype
#> 1 relation 1903516 boundary administrative          8   0.681334        city
#>               name               display_name
#> 1 Thành phố Hà Nội Thành phố Hà Nội, Việt Nam
#>                                        boundingbox
#> 1 20.5645154, 21.3852777, 105.2889615, 106.0200725

raw2 <- query_api(
  "http://nominatim.openstreetmap.org/reverse",
  get_api_query("osm", custom_parameters = list(lat = 38.895865, lon = -77.0307713))
)

extract_reverse_results("osm", jsonlite::fromJSON(raw2$content))
#> # A tibble: 1 × 24
#>   display_name      place_id licence osm_type osm_id osm_lat osm_lon class type 
#>   <chr>                <int> <chr>   <chr>     <int> <chr>   <chr>   <chr> <chr>
#> 1 L’Enfant's plan,…   3.20e8 Data ©… way      9.00e8 38.895… -77.03… tour… artw…
#> # ℹ 15 more variables: place_rank <int>, importance <dbl>, addresstype <chr>,
#> #   name <chr>, tourism <chr>, road <chr>, suburb <chr>, borough <chr>,
#> #   city <chr>, state <chr>, `ISO3166-2-lvl4` <chr>, postcode <chr>,
#> #   country <chr>, country_code <chr>, boundingbox <list>
# }