是否有任何服务返回给定城市/州的邮政编码?

发布于 2024-08-17 06:48:27 字数 44 浏览 4 评论 0 原文

有没有可用的服务器可以用来根据城市/州获取邮政编码?

谢谢

is there any server available that i can use for getting zip codes on the basis on city/state ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2024-08-24 06:48:27

您可以使用 geonames 邮政编码搜索。例如:

http://ws.geonames.org /postalCodeSearch?adminCode1=CA&placename=San+Francisco&maxRows=3

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<totalResultsCount>76</totalResultsCount>
<code>
<postalcode>94102</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.781334</lat>
<lng>-122.416728</lng>
<adminCode1>CA</adminCode1>

<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94103</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.77254</lat>

<lng>-122.414664</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94107</postalcode>
<name>San Francisco</name>

<countryCode>US</countryCode>
<lat>37.762147</lat>
<lng>-122.397099</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>

</code>
</geonames>

You can use geonames postal code search. For example:

http://ws.geonames.org/postalCodeSearch?adminCode1=CA&placename=San+Francisco&maxRows=3

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<totalResultsCount>76</totalResultsCount>
<code>
<postalcode>94102</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.781334</lat>
<lng>-122.416728</lng>
<adminCode1>CA</adminCode1>

<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94103</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.77254</lat>

<lng>-122.414664</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94107</postalcode>
<name>San Francisco</name>

<countryCode>US</countryCode>
<lat>37.762147</lat>
<lng>-122.397099</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>

</code>
</geonames>
青丝拂面 2024-08-24 06:48:27

使用美国邮政服务 HTTP/XML API

您可以根据美国邮政上的此页面 记录其基于 XML 的 Web API 的服务网站,特别是 此 PDF 文档,他们有一个 URL,您可以在其中发送包含地址减去邮政编码的 XML 请求,他们将使用包含完整地址的 XML 文档进行响应。

不过,您不能仅使用城市和州进行查找,因为一个城市可以包含多个邮政编码,因此您还需要传递街道地址。

根据他们的文档,您的请求将如下所示:

GET http://SERVERNAME/ShippingAPITest.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest%20USERID="xxxxxxx"><Address ID="0"><Address1></Address1> <Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>

以下是您将收到的回复:

<?xml version="1.0"?> 
<ZipCodeLookupResponse> 
    <Address ID="0"> 
        <Address2>6406 IVY LN</Address2> 
        <City>GREENBELT</City> 
        <State>MD</State> 
        <Zip5>20770</Zip5> 
        <Zip4>1441</Zip4> 
    </Address> 
</ZipCodeLookupResponse>

USPS 确实要求您在使用 API 之前向他们注册,但是,据我所知可以看出,访问是免费的。顺便说一句,他们的 API 还有一些其他功能:您可以进行地址标准化和邮政编码查找,以及整套跟踪、运输、标签等。

You can use 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 3.0 (page 13) of this PDF document, they have a URL where you can send an XML request containing an address minus the Zip Code and they will respond with an XML document containing the complete address.

You can't do a lookup with just a city and state though, because a single city can contain multiple ZIP codes, so you need to pass the street address as well.

According to their documentation, this is what your request would look like:

GET http://SERVERNAME/ShippingAPITest.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest%20USERID="xxxxxxx"><Address ID="0"><Address1></Address1> <Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>

And here's what you would receive back:

<?xml version="1.0"?> 
<ZipCodeLookupResponse> 
    <Address ID="0"> 
        <Address2>6406 IVY LN</Address2> 
        <City>GREENBELT</City> 
        <State>MD</State> 
        <Zip5>20770</Zip5> 
        <Zip4>1441</Zip4> 
    </Address> 
</ZipCodeLookupResponse>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文