Geocodes (finds latitude and longitude of) a location using the Google Geocoding API. Note: To use Google's Geocoding API, you must first enable the API in the Google Cloud Platform Console. See register_google().
location: a character vector of street addresses or place names (e.g. "1600 pennsylvania avenue, washington dc" or "Baylor University")
output: amount of output, "latlon", "latlona", "more", or "all"
source: "google" for Google (note: "dsk" is defunct)
force: force online query even if cached.
urlonly: return only the url?
override_limit: override the current query rate
nameType: in some cases, Google returns both a long name and a short name. this parameter allows the user to specify which to grab.
ext: top level domain (e.g. "com", "co.nz"); helpful for non-US users
inject: character string to add to the url or named character vector of key-value pairs to be injected (e.g. c("a" = "b") get converted to "a=b" and appended to the query)
...: In mutate_geocode(), arguments to pass to geocode(). In write_geocode_cache(), arguments to pass to saveRDS().
data: a data frame or equivalent
path: path to file
overwrite: in load_geocode_cache(), should the current cache be wholly replaced with the one on file?
Returns
If output is "latlon", "latlona", or "more", a tibble (classed data frame). If "all", a list.
Details
Note: geocode() uses Google's Geocoding API to geocode addresses. Please take care not to disclose sensitive information. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8972108/ suggest various alternative options for such data.
Examples
## Not run: requires Google API key, see ?register_google
## basic usage######################################### geocoding is most commonly used for addressesgeocode("1600 Amphitheatre Parkway, Mountain View, CA")geocode("1600 Amphitheatre Parkway, Mountain View, CA", urlonly =TRUE)# google can also geocode colloquial names of placesgeocode("the white house")# geocode can also accept character vectors of placesgeocode(c("the white house","washington dc"))## types of output########################################geocode("waco texas")geocode("waco texas", output ="latlona")geocode("waco texas", output ="more")str(geocode("waco texas", output ="all"))geocode(c("waco, texas","houston, texas"))geocode(c("waco, texas","houston, texas"), output ="latlona")geocode(c("waco, texas","houston, texas"), output ="all")%>% str(4)## mutate_geocode######################################### mutate_geocode is used to add location columns to an existing dataset# that has location informationdf <- data.frame( address = c("1600 Pennsylvania Avenue, Washington DC","","houston texas"), stringsAsFactors =FALSE)mutate_geocode(df, address)df %>% mutate_geocode(address)## known issues######################################### in some cases geocode finds several locations## End(Not run)