开发者

Webservice to get City Names by giving Zip Codes [closed]

开发者 https://www.devze.com 2023-03-10 00:46 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 9 years ago.

Improve this question

I need a reliable webserivce which gives corresponding city name by passing zi开发者_如何转开发p code. This webservice should work at any time. This webservice will be used in the production also.


I found a couple of ways to do this with web based APIs. I think the US Postal Service would be the most accurate, since Zip codes are their thing, but Ziptastic looks much easier.

Using the US Postal Service HTTP/XML API

According to this page on the US Postal Service website which documents their XML based web API, specifically Section 4.0 (page 22) of this PDF document, they have a URL where you can send an XML request containing a 5 digit Zip Code and they will respond with an XML document containing the corresponding City and State.

According to their documentation, here's what you would send:

http://SERVERNAME/ShippingAPITest.dll?API=CityStateLookup&XML=<CityStateLookupRequest%20USERID="xxxxxxx"><ZipCode ID= "0"><Zip5>90210</Zip5></ZipCode></CityStateLookupRequest>

And here's what you would receive back:

<?xml version="1.0"?> 
<CityStateLookupResponse> 
    <ZipCode ID="0"> 
        <Zip5>90210</Zip5> 
        <City>BEVERLY HILLS</City> 
        <State>CA</State> 
    </ZipCode> 
</CityStateLookupResponse>

USPS does require that you register with them before you can use the API, but, as far as I could tell, there is no charge for access. By the way, their API has some other features: you can do Address Standardization and Zip Code Lookup, as well as the whole suite of tracking, shipping, labels, etc.

Using the Ziptastic HTTP/JSON API

This is a pretty new service, but according to their documentation, it looks like all you need to do is send a GET request to http://ziptasticapi.com, like so:

GET http://ziptasticapi.com/48867

And they will return a JSON object along the lines of:

{"country": "US", "state": "MI", "city": "OWOSSO"}

Indeed, it works. You can test this from a command line by doing something like:

curl http://ziptasticapi.com/48867 


http://www.geonames.org/

http://www.geonames.org/postal-codes/

has it for multiple countries


perhaps http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP would work for you


The Yahoo PlaceFinder API will work for this type of query.

http://developer.yahoo.com/geo/placefinder/guide/index.html

I believe that

http://where.yahooapis.com/geocode?appid=<appID>&postal=<zipCode>

will get you what you're looking for.


Also http://www.zipwise.com/webservices gives XML and JSON results for free for zip code lookups, radius searches, reverse lookups, and latitude/longitude stuff.


This may suite your need if you want something to obtain city/state information:

http://www.usps.com/webtools/address.htm

Its a API in which you sign up for.

0

精彩评论

暂无评论...
验证码 换一张
取 消