Check whether a place is a valid place or misspelling by matching against the
Google Geocoding search result. Use the httr::GET()
to send a request to
the Google Maps API for geocoding information. The query will concatenate all
the geographical information that is passed in into a long string. Then the
function pulls the formatted_address
endpoint of the API results and then
identifies and extracts the long name field from the API locality result
and compare it against the input to see if the input and output match up.
Note that you will need to pass in your Google Maps Place API key to the
key
argument.
check_city(city = NULL, state = NULL, zip = NULL, key = NULL, guess = FALSE)
A string of city name to be submitted to the Geocode API.
Optional. The state associated with the city
.
Optional. Supply a string of ZIP code to increase precision.
A character string to be passed into key
. Save your key as
"GEOCODE_KEY" using Sys.setenv()
or by editing your .Renviron
file.
logical; Should the function return a single row tibble containing the original data sent and the multiple components returned by the Geocode API.
A logical value by default. If the city returned by the API
comes back the same as the city input, the function will evaluate to
TRUE
, in all other circumstances (including API errors) FALSE
is returned.
If the the guess
argument is set to TRUE
, a tibble with 1 row and six
columns is returned:
original_city
: The city
value sent to the API.
original_state
: The state
value sent to the API.
original_zip
: The zip
value sent to the API.
check_city_flag
: logical; whether the guessed city matches.
guess_city
: The legal city guessed by the API.
guess_place
: The generic locality guessed by the API.
https://developers.google.com/maps/documentation/geocoding/overview?csw=1
Other geographic normalization functions:
abbrev_full()
,
abbrev_state()
,
expand_abbrev()
,
expand_state()
,
fetch_city()
,
normal_address()
,
normal_city()
,
normal_state()
,
normal_zip()
,
str_normal()