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 single string. Then the function pulls the formatted_address endpoint of the API results and extracts the the first field of the result. Note that you will need to pass in your Google Maps Place API key with the key argument.

fetch_city(address = NULL, key = NULL)

Arguments

address

A vector of street addresses. Sent to the API as one string.

key

A character containing your alphanumeric Google Maps API key.

Value

A character vector of formatted address endpoints from Google. This will include all the fields from street address, city, state/province, zipcode/postal code to country/regions. NA_character_ is returned for all errored API calls.