I'm using the googleway
package to collect geolocation data for a long list of locations, and I want to figure out how to do it better, e.g. with purrr
.
Here's a single example:
library(googleway)
# you'll need an API key
loc <- google_geocode("151 third st. sf, ca", key = my_key)
Here's the output I get:
loc <- structure(list(results = structure(list(address_components = list(
structure(list(long_name = c("151", "3rd Street", "South Beach",
"San Francisco", "San Francisco County", "California", "United States",
"94103", "3107"), short_name = c("151", "3rd St", "South Beach",
"SF", "San Francisco County", "CA", "US", "94103", "3107"
), types = list("street_number", "route", c("neighborhood",
"political"), c("locality", "political"), c("administrative_area_level_2",
"political"), c("administrative_area_level_1", "political"
), c("country", "political"), "postal_code", "postal_code_suffix")), .Names = c("long_name",
"short_name", "types"), class = "data.frame", row.names = c(NA,
9L))), formatted_address = "151 3rd St, San Francisco, CA 94103, USA",
geometry = structure(list(location = structure(list(lat = 37.7859072,
lng = -122.4008003), .Names = c("lat", "lng"), class = "data.frame", row.names = 1L),
location_type = "ROOFTOP", viewport = structure(list(
northeast = structure(list(lat = 37.7872561802915,
lng = -122.399451319709), .Names = c("lat", "lng"
), class = "data.frame", row.names = 1L), southwest = structure(list(
lat = 37.7845582197085, lng = -122.402149280291), .Names = c("lat",
"lng"), class = "data.frame", row.names = 1L)), .Names = c("northeast",
"southwest"), class = "data.frame", row.names = 1L)), .Names = c("location",
"location_type", "viewport"), class = "data.frame", row.names = 1L),
place_id = "ChIJ23gaZn2AhYARH-8DeKxyEw0", plus_code = structure(list(
compound_code = "QHPX+9M South of Market, San Francisco, CA, United States",
global_code = "849VQHPX+9M"), .Names = c("compound_code",
"global_code"), class = "data.frame", row.names = 1L), types = list(
"street_address")), .Names = c("address_components",
"formatted_address", "geometry", "place_id", "plus_code", "types"
), class = "data.frame", row.names = 1L), status = "OK"), .Names = c("results",
"status"))
I'm particularly interested in a few pieces, like
loc[["results"]][["geometry"]][["location"]]
and
loc[["results"]][["geometry"]][["viewport"]]
.
Let's say I have a list that combines multiple of these:
locs <- list(loc, loc, loc)
How could I extract all the "locations" and "viewports" from every component of the list?