5

Given a latitude and longitude, what is the easiest way to find the name of the city and the US zip code of that location.

(This is similar to https://stackoverflow.com/questions/23572/latitude-longitude-database, except I want to convert in the opposite direction.)


Related question: Get street address at lat/long pair

8 Answers 8

3

Any of the online services mentioned and their competitors offer "reverse geocoding" which does what you ask--convert lon/lat coordinates into a street address of some-sort.

If you only need the zip codes and/or cities, then I would obtain the Zip Code database and urban area database from the US Census Bureau which is FREE (paid for by your tax dollars). http://www.census.gov/geo/www/cob/zt_metadata.html.

From there, you can either come up with your own search algorithm for the spatial data or make use of one of a spatial databases such as Microsoft SQL Server, PostGIS, Oracle Spatial, ArcSDE, etc.

Update: The 2010 Census data can be found at: http://www2.census.gov/census_2010/

1
  • Your link is out of date. You are linking to data from the 2000 Census, which is ages ago.
    – James D
    May 8, 2012 at 17:35
2

This is the web service to call. http://developer.yahoo.com/search/local/V2/localSearch.html

This site has ok web services, but not exactly what you're asking for here. http://www.usps.com/webtools/

1

You have two main options:

Use a Reverse Geocoding Service

  • Google's can only be used in conjunction with an embedded Google Map on the same page, so I don't recommend it unless that is what you are doing.
  • Yahoo has a good one, see http://developer.yahoo.com/search/local/V3/localSearch.html
  • I've not used OpenStreetMap's. Their maps look very detailed and thorough, and are always getting better, but I'd be worried about latency and reliability, and whether their address data is complete (address data is not directly visible on a map, and OpenStreetMap is primarily an interactive map).

Use a Map of the ZIP Codes

The US Census publishes a map of US ZIP codes here. They build this from their smallest statistical unit, a Census Block, which corresponds to a city block in most cases. For each block, they find what ZIP code is most common on that block (most blocks have only one ZIP code, but blocks near the border between ZIP codes might have more than one). They then aggregate all the blocks with a given ZIP code into a single area called a Zip Code Tabulation Area. They publish a map of those areas in ESRI shapefile format.

I know about this because I wrote a Java Library and web service that (among other things) uses this map to return the ZIP code for a given latitude and longitude. It is a commercial product, so it won't be for everyone, but it is fast, easy to use, and solves this specific problem without an API. You can read about this product here:

http://askgeo.com/database/UsZcta2010

And about all of your geographic offerings here:

http://askgeo.com

Unlike reverse geocoding solutions, which are only available as Web APIs because running your own service would be extremely difficult, you can run this library on your own server and not depend on an external resource.

0

If you call volume to the service gets up too high, you should definitely consider getting your own set of postal data. In most cases, that will provide all of the information that you need, and there are plenty of db tools for indexing location data (i.e. PostGIS for PostgreSQL).

1
  • SQL databases are terrible for GIS applications. Yes, they have plug-ins to help, but they are hard to set up and provide bad performance. And they only query that they can do reasonably well is the nearest record in the database, which is not very good for finding the ZIP code for a query point, since the nearest point could easily be (and often is) in a different ZIP code. You should either use a proper reverse geocoding API that provides a street address for lat/lon, or a map of the ZIP code polygons.
    – James D
    May 8, 2012 at 17:33
0

You can buy a fairly inexpensive subscription to zipcodes with lat and long info here: http://www.zipcodedownload.com/

1
  • ZIP codes are not a single lat/lon pair. If you just find the nearest entry in the database you reference, you'll get the wrong ZIP code a lot of the time.
    – James D
    May 8, 2012 at 17:26
0

Or google's reverse geocoding

link

http://maps.google.com/maps/geo?output=xml&q={0},{1}&key={2}&sensor=true&oe=utf8

where 0 is latitude 1 is longitude

1
  • The trouble with Google's reverse geocoding is that you are only allowed to use it in conjunction with an embedded Google Map.
    – James D
    May 8, 2012 at 17:28
-1

geonames has an extensive set of ws that can handle this (among others):

http://www.geonames.org/export/web-services.html#findNearbyPostalCodes
http://www.geonames.org/export/web-services.html#findNearbyPlaceName

1
  • GeoNames uses a database of point locations (city centers, schools, public buildings, parks, points of interest, etc.) and finds the one nearest to your query point. There is no guarantee that the nearest point of interest will have the same ZIP code as your query point. A proper geocoding solution that returns the nearest street address does not have this problem, but GoeNames does not provide that.
    – James D
    May 8, 2012 at 17:30
-1

Another reverse geocoding provider that hasn't been listed here yet is OpenStreetMap: you can use their Nominatim search service.

OSM has the (potentially?) added bonus of being entirely user editable (wiki-like) and thus having a very liberal licencing scheme of all this data. Think of this of open source map data.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.