## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = nzchar(Sys.getenv("CLOSECITY_KEY"))
)
library(closecity)
close <- closecity::close_client(api_key = Sys.getenv("CLOSECITY_KEY"))

## -----------------------------------------------------------------------------
# amenity_types <- close$destination_types()
# supermarket_type <- amenity_types[amenity_types$label == "grocery_stores", ]$dest_type_id
# 
# providence_ri <- close$places(q = "Providence")[1, ]
# start_lon <- providence_ri$lon
# start_lat <- providence_ri$lat

## -----------------------------------------------------------------------------
# walk_times <- close$point_summary(lat = start_lat, lon = start_lon, mode = "walk")
# walk_times <- merge(
#   walk_times,
#   amenity_types[, c("dest_type_id", "name")],
#   by = "dest_type_id"
# )
# walk_times[order(walk_times$travel_time), c("name", "travel_time")]

## -----------------------------------------------------------------------------
# nearby_supermarkets <- close$point_pois(
#   lat = start_lat,
#   lon = start_lon,
#   mode = "walk",
#   type = supermarket_type,
#   max_minutes = 30
# )
# 
# city_boundary <- close$place_boundary(geoid = providence_ri$geoid)
# closecity::close_map(
#   x = nearby_supermarkets,
#   fill = "travel_time",
#   boundary = city_boundary,
#   label = "name",
#   mark = c(start_lon, start_lat)
# )

## -----------------------------------------------------------------------------
# rings <- close$isochrone(
#   lon = start_lon,
#   lat = start_lat,
#   mode = "walk",
#   direction = "from",
#   contours = c(10, 20, 30),
#   format = "geojson"
# )
# closecity::close_map(x = rings, fill = "contour")

## -----------------------------------------------------------------------------
# walk <- close$isochrone(
#   lon = start_lon,
#   lat = start_lat,
#   mode = "walk",
#   direction = "from",
#   minutes = 30,
#   format = "geojson"
# )
# transit <- close$isochrone(
#   lon = start_lon,
#   lat = start_lat,
#   mode = "transit",
#   direction = "from",
#   minutes = 30,
#   format = "geojson"
# )
# 
# closecity::close_map(x = walk, color = "#058040")
# closecity::close_map(x = transit, color = "#202a5b")

