Get geocoded coordinates using the Google Maps Geocoding API
Get geocoded coordinates using the Google Maps Geocoding API
mp_geocode( addresses, region = NULL, postcode = NULL, bounds = NULL, key, quiet = FALSE )
addresses |
Addresses to geocode, as |
region |
The region code, specified as a ccTLD ("top-level domain") two-character value (e.g. |
postcode |
Vector of postal codes to filter the address match by (optional); Note that this is a component filter, which means that for each address, Google will search only within the corresponding postal code if non-missing |
bounds |
A preferred bounding box, specified as a numeric vector with four values xmin/ymin/xmax/ymax (in latitude/longitude) representing the coordinates of the southwest and northeast corners, e.g. as returned by function 'sf::st_bbox'. This can be a single vector (in which case it is replicated) or a |
key |
Google APIs key (optional) |
quiet |
Logical; suppress printing geocode request statuses |
list
of XML documents with Google Maps Geocoding API responses, one item per element in addresses
Use function mp_get_points
to extract locations as sf
point layer
Use function mp_get_bounds
to extract location bounds as sf
polygonal layer
# Built-in reponse example library(xml2) doc = list("Tel-Aviv" = as_xml_document(response_geocode)) pnt = mp_get_points(doc) bounds = mp_get_bounds(doc) ## Not run: # Text file with API key key = readLines("~/key") # Basic use addresses = c("Rehovot", "Beer-Sheva", "New-York") doc = mp_geocode(addresses, key = key) pnt = mp_get_points(doc) pnt # Using the 'region' parameter doc = mp_geocode(addresses = "Toledo", key = key) mp_get_points(doc) doc = mp_geocode(addresses = "Toledo", region = "es", key = key) mp_get_points(doc) # Various addresses addresses = c( "Baker Street 221b, London", "Brandenburger Tor, Berlin", "", "Platz der Deutschen Einheit 1, Hamburg", "Arc de Triomphe de l'Etoile, Paris", NA ) doc = mp_geocode(addresses, key = key) pnt = mp_get_points(doc) pnt # Specifying a bounding box b = c(-118.604794, 34.172684, -118.500938, 34.236144) # Bounds as xmin/ymin/xmax/ymax result = mp_geocode(addresses = "Winnetka", key = key) mp_get_points(result) result = mp_geocode(addresses = "Winnetka", bounds = b, key = key) mp_get_points(result) result = mp_geocode(addresses = rep("Winnetka", 3), bounds = list(b, NA, b), key = key) mp_get_points(result) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.