Learn R Programming

ggmap (version 3.0.1)

geocode: Geocode

Description

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().

Usage

geocode(
  location,
  output = c("latlon", "latlona", "more", "all"),
  source = c("google", "dsk"),
  force = ifelse(source == "dsk", FALSE, TRUE),
  urlonly = FALSE,
  override_limit = FALSE,
  nameType = c("long", "short"),
  ext = "com",
  inject = "",
  ...
)

mutate_geocode(data, location, ...)

geocodeQueryCheck()

geocode_cache()

write_geocode_cache(path, ...)

load_geocode_cache(path, overwrite = FALSE)

clear_geocode_cache(path)

Value

If output is "latlon", "latlona", or "more", a tibble (classed data frame). If "all", a list.

Arguments

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?

Author

David Kahle david@kahle.io

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.

See Also