Here is some code to programmatically grab the name of a US county provided to one US city / state using the Google Maps API. This code is slow / inefficient and has no error handling. However, it worked reliably for me to fit counties with a list of ~ 1000 cities.
#Set up googlemaps API import googlemaps google_maps = googlemaps.Client(key='API_KEY_GOES_HERE')
This gives:
>>> county_name Fulton County
Cautions:
- code will be broken if google_maps.geocode () is not passed a valid address
- some addresses will not return data matching 'Administrative_area_level_2'
- this does not solve the problem of US cities that span multiple counties. Instead, I think the API just returns the county associated with a single latitude / longitude associated with
address_string
source share