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)

See also

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.02945 105.8544 282631247 #> 2 21.04456 105.9187 151044464 #> 3 20.99176 105.7968 246307827 #> 4 21.04778 105.8143 53777587 #> 5 21.03667 105.7827 267001250 #> 6 21.02930 105.8572 53727173 #> 7 21.03669 105.7827 81907432 #> licence #> 1 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> 2 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> 3 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> 4 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> 5 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> 6 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> 7 Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright #> osm_type osm_id boundingbox #> 1 relation 1903516 20.5645154, 21.3852777, 105.2848986, 106.0200725 #> 2 way 208502808 21.0437964, 21.0453238, 105.9181301, 105.91946 #> 3 way 736412443 20.9907136, 20.9928221, 105.795787, 105.7978094 #> 4 node 4753131321 21.0477253, 21.0478253, 105.8142571, 105.8143571 #> 5 way 872332878 21.0365605, 21.0367753, 105.7821469, 105.783248 #> 6 node 4747249104 21.029253, 21.029353, 105.8571969, 105.8572969 #> 7 node 8124813873 21.0366379, 21.0367379, 105.7826432, 105.7827432 #> display_name #> 1 Thành phố Hà Nội, Việt Nam #> 2 British International School, Hanoi, Hoa Lan 2, Vinhomes Riverside, Phường Phúc Lợi, Quận Long Biên, Thành phố Hà Nội, 100000, Việt Nam #> 3 Đại học quốc gia Hà Nội, 182, Đường Lương Thế Vinh, Phường Trung Văn, Quận Nam Từ Liêm, Thành phố Hà Nội, 1000001, Việt Nam #> 4 Venezuelan Embassy in Hanoi, Vietnam, 111, Phố Trích Sài, Phường Bưởi, Quận Tây Hồ, Thành phố Hà Nội, 1000, Việt Nam #> 5 Đại học Quốc gia Hà Nội, Đường Xuân Thủy, Quận Cầu Giấy, Thành phố Hà Nội, 122000, Việt Nam #> 6 Đại sứ quán Đan Mạch tại Hà Nội, Việt Nam, 194, Đường Trần Quang Khải, Lý Thái Tổ, Quận Hoàn Kiếm, Thành phố Hà Nội, 110905, Việt Nam #> 7 Đại học Quốc gia Hà Nội, Đường Xuân Thủy, Quận Cầu Giấy, Thành phố Hà Nội, 122000, Việt Nam #> class type importance #> 1 boundary administrative 0.6282962 #> 2 building school 0.4099978 #> 3 amenity university 0.3945655 #> 4 office diplomatic 0.2110000 #> 5 railway station 0.0010000 #> 6 office diplomatic 0.0010000 #> 7 railway stop 0.0010000 #> icon #> 1 https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png #> 2 <NA> #> 3 https://nominatim.openstreetmap.org/ui/mapicons//education_university.p.20.png #> 4 <NA> #> 5 https://nominatim.openstreetmap.org/ui/mapicons//transport_train_station2.p.20.png #> 6 <NA> #> 7 <NA>
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 × 16 #> display_name place_id licence osm_type osm_id osm_lat osm_lon tourism #> <chr> <int> <chr> <chr> <int> <chr> <chr> <chr> #> 1 Freedom Plaza, … 284009208 Data © Ope… relation 8.06e6 38.895… -77.03… Freedo… #> # … with 8 more variables: house_number <chr>, road <chr>, city <chr>, #> # state <chr>, postcode <chr>, country <chr>, country_code <chr>, #> # boundingbox <list>
# }