geolocationgeocodinggeo

What's the best way to lookup the US county a US city resides in?


I'm looking for the best/easiest way to programmatically grab the name of the US county a given US city resides in. It doesn't seem there's a straightforward API available for such a (seemingly simple) task?


Solution

  • You can download a freely-available database of county/city/zip code info such as this one: http://www.unitedstateszipcodes.org/zip-code-database/ (no need to register or pay)

    Import it whole, or a subsection of it, into a local, persistent data store (such as a database) and query it whenever you need to look up a city's county

    Note: County info has disappeared from the originally-linked .csv file since this answer was posted. This link no longer contains county information: http://federalgovernmentzipcodes.us/free-zipcode-database.csv