Finding City and Zip Code for a Location

后端 未结 8 866
既然无缘
既然无缘 2020-12-28 10:45

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.

8条回答
  •  生来不讨喜
    2020-12-28 11:27

    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.

提交回复
热议问题