We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
使用 GeoCoding API
例如,要查找 zip 77379,请使用如下请求:
https://maps.googleapis。 com/maps/api/geocode/json?address=77379&sensor=true&key=YOUR_GOOGLE_PLATFORM_API_KEY
Use the GeoCoding API
For example, to lookup zip 77379 use a request like this:
https://maps.googleapis.com/maps/api/geocode/json?address=77379&sensor=true&key=YOUR_GOOGLE_PLATFORM_API_KEY
我发现了几种使用基于 Web 的 API 来实现此目的的方法。我认为美国邮政服务是最准确的,因为邮政编码是他们的事,但是Ziptastic 看起来更容易。
使用美国邮政服务 HTTP/XML API
根据此 页面美国邮政服务网站记录了其基于 XML 的 Web API,特别是 此 PDF 文档,他们有一个 URL,您可以在其中发送包含 5 位邮政编码的 XML 请求,他们将使用包含相应城市和州的 XML 文档进行响应。
根据他们的文档,您将发送以下内容:
以下是您将收到的返回内容:
USPS 确实要求您在使用 API 之前向他们注册,但是,据我所知,访问无需付费。顺便说一句,他们的 API 还有一些其他功能:您可以进行地址标准化和邮政编码查找,以及整套跟踪、运输、标签等。
使用 Ziptastic HTTP/JSON API (不再支持)
更新:自 2017 年 8 月 13 日起,Ziptastic 现已成为付费 API可以在此处找到
这是一项相当新的服务,但根据他们的文档,它看起来像您需要做的就是向 http://ziptasticapi.com 发送 GET 请求,如下所示:
他们将返回JSON 对象的思路是:
确实,它有效。您可以通过执行以下操作从命令行测试这一点:
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:
And here's what you would receive back:
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 (no longer supported)
Update: As of August 13, 2017, Ziptastic is now a paid API and can be found here
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:
And they will return a JSON object along the lines of:
Indeed, it works. You can test this from a command line by doing something like:
几个月前,我对我的一个项目有同样的要求。我搜索了一下并找到了以下解决方案。这不是唯一解决方案,但我发现它是更简单的解决方案之一。
使用 http://www.webservicex.net/uszip.asmx 处的 Web 服务。
具体来说是
GetInfoByZIP()
方法。您将能够通过任何邮政编码(
ex: 40220
)进行查询,并且您将收到如下回复...希望这有帮助...
couple of months back, I had the same requirement for one of my projects. I searched a bit for it and found out the following solution. This is not the only solution but I found it to one of the simpler one.
Use the webservice at http://www.webservicex.net/uszip.asmx.
Specifically
GetInfoByZIP()
method.You will be able to query by any zipcode (
ex: 40220
) and you will have a response back as the following...Hope this helps...