geocode: geocode a location using the google maps geocode API.

Description Usage Arguments Value Examples

View source: R/geoCode.R

Description

The function geocodes a single address given as a character string. Be as specific as possible, including the country or postcode to avoid ambiguity. To avoid loss of accuracy when geocoding a lat/lng string, the geoCode function does not geocode lat/lng strings but instead returns the same string as a dataframe.

Usage

1
2
3
4
5
6
geocode(
  address,
  api_key = Sys.getenv("google_api_key"),
  verbose = FALSE,
  return_all = TRUE
)

Arguments

address

character string with address to be geocoded. Be as specific as possible to avoid ambiguity.

api_key

character string containing api key for the google maps geocode api. You can generate one for free in your google cloud console.

verbose

logical value. If TRUE, echos the input address

return_all

logical value. Some locations may return more than one geocoded result. If you only want one row returned set return_all = FALSE.

Value

a data.frame containing the coordinates, location type and approximate address.

Examples

1
2
3
4
5
6
7
## Not run: 
geocode('London Bridge, London, UK', return_all = FALSE)

#  lat        lng             type                           address
#  51.50788 -0.0877321 GEOMETRIC_CENTER London Bridge, London SE1 9RA, UK

## End(Not run)

Chrisjb/RDistanceMatrix documentation built on Jan. 27, 2021, 9:12 p.m.