check_city {campfin}R Documentation

Check whether an input is a valid place with Google Maps API

Description

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.

Usage

check_city(city = NULL, state = NULL, zip = NULL, key = NULL, guess = FALSE)

Arguments

city

A string of city name to be submitted to the Geocode API.

state

Optional. The state associated with the city.

zip

Optional. Supply a string of ZIP code to increase precision.

key

A character string to be passed into key. Save your key as "GEOCODE_KEY" using Sys.setenv() or by editing your .Renviron file.

guess

logical; Should the function return a single row tibble containing the original data sent and the multiple components returned by the Geocode API.

Value

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:

See Also

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


[Package campfin version 1.0.11 Index]