The geocode() function converts addresses into geographic coordinates (latitude and longitude). It works on dataframes and supports various geocoding services via the method argument.
Key features:
- Batch geocoding: Automatically used if the service supports it.
- Rate limiting: Automatically respects the usage policies of the selected service.
- Data handling: Handles duplicate, NA, and blank inputs by only submitting unique values while preserving original row counts.
- Full results: By default, only latitude and longitude are returned. Set
full_results = TRUE to retrieve all available data from the service.
library(dplyr, warn.conflicts = FALSE)
library(tidygeocoder)
some_addresses <- tibble::tribble(
~name, ~addr,
"White House", "1600 Pennsylvania Ave NW, Washington, DC",
"Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111",
"Willis Tower", "233 S Wacker Dr, Chicago, IL 60606"
)
# Geocode addresses using the OpenStreetMap (osm) method
lat_longs <- some_addresses %>%
geocode(addr, method = 'osm', lat = latitude, long = longitude)