- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用某种 API 服务来获取邮政编码并返回与该邮政编码匹配的所有城市。
USPS 网站上的手动查找会执行此操作,而 Crate and Barrel 在其结账时会执行此操作。
USPS 的邮政编码 API 似乎只能返回一个城市。我查看了 Geonames 数据库,但它似乎也只为每个邮政编码的一个城市设置。
有办法实现这一点吗?
最佳答案
我将继续发布 @Matt 的答案,因为我已经使用了 SmartyStreets ZIP Code API就是为了这个目的。您可以通过以下三种方式之一查询此 API:
对于单个邮政编码(这就是您所询问的内容),这是一个简单的 GET
请求:
curl -v 'https://us-zipcode.api.smartystreets.com/lookup?
auth-id=YOUR+AUTH-ID+HERE&
auth-token=YOUR+AUTH-TOKEN+HERE&
zipcode=65202'
响应(具有有效的 AUTH-ID
和 AUTH-TOKEN
)是:
[
{
"input_index": 0,
"city_states": [
{
"city": "Columbia",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": true
},
{
"city": "Hinton",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Lindbergh",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Midway",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Murry",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Prathersville",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Shaw",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Stephens",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
}
],
"zipcodes": [
{
"zipcode": "65202",
"zipcode_type": "S",
"default_city": "Columbia",
"county_fips": "29019",
"county_name": "Boone",
"state_abbreviation": "MO",
"state": "Missouri",
"latitude": 38.99775,
"longitude": -92.30798,
"precision": "Zip5",
"alternate_counties": [
{
"county_fips": "29027",
"county_name": "Callaway",
"state_abbreviation": "MO",
"state": "Missouri"
}
]
}
]
}
]
如您所见,这给出了与图片示例相同的城市列表。它还包含有关列表中第一个 city_state
的更多详细信息。
为了完整起见,下面是一个示例请求,演示了所有三个查询选项。 (注意:对于单个邮政编码之外的任何请求,API 需要 POST
调用):
curl -v 'https://us-zipcode.api.smartystreets.com/lookup?
auth-id=YOUR+AUTH-ID+HERE&
auth-token=YOUR+AUTH-TOKEN+HERE'
-H "Content-Type: application/json"
--data-binary '
[
{
"zipcode":"12345"
},
{
"city":"North Pole",
"state":"AK"
},
{
"city":"cupertino",
"state":"CA",
"zipcode":"95014"
}
]'
这是该示例请求的响应:
[
{
"input_index": 0,
"city_states": [
{
"city": "Schenectady",
"state_abbreviation": "NY",
"state": "New York",
"mailable_city": true
},
{
"city": "General Electric",
"state_abbreviation": "NY",
"state": "New York",
"mailable_city": false
},
{
"city": "Schdy",
"state_abbreviation": "NY",
"state": "New York",
"mailable_city": false
}
],
"zipcodes": [
{
"zipcode": "12345",
"zipcode_type": "U",
"default_city": "Schenectady",
"county_fips": "36093",
"county_name": "Schenectady",
"state_abbreviation": "NY",
"state": "New York",
"latitude": 42.81565,
"longitude": -73.94232,
"precision": "Zip5"
}
]
},
{
"input_index": 1,
"city_states": [
{
"city": "North Pole",
"state_abbreviation": "AK",
"state": "Alaska",
"mailable_city": true
}
],
"zipcodes": [
{
"zipcode": "99705",
"zipcode_type": "S",
"default_city": "North Pole",
"county_fips": "02090",
"county_name": "Fairbanks North Star",
"state_abbreviation": "AK",
"state": "Alaska",
"latitude": 64.77911,
"longitude": -147.36885,
"precision": "Zip5"
}
]
},
{
"input_index": 2,
"city_states": [
{
"city": "Cupertino",
"state_abbreviation": "CA",
"state": "California",
"mailable_city": true
}
],
"zipcodes": [
{
"zipcode": "95014",
"zipcode_type": "S",
"default_city": "Cupertino",
"county_fips": "06085",
"county_name": "Santa Clara",
"state_abbreviation": "CA",
"state": "California",
"latitude": 37.32056,
"longitude": -122.03865,
"precision": "Zip5"
}
]
}
]
希望对您有所帮助!
编辑 - 我已经用特定于该问题的示例更新了此内容。感谢@AmyAnuszewski 指出这一点。
关于zipcode - 通过一次邮政编码搜索返回多个城市、州建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24014750/
我有一个邮政编码范围的数据库: id name zip_start zip_end 1 A 1212 1216 2 B 9100
我安装了 SmartyStreets在我的表单上,除了未填充的邮政编码外,一切正常。我还在 SmartyStreets 的页面上注意到,您可以在其中尝试邮政编码未填充的示例。这是否正常,API 或我的
我想使用某种 API 服务来获取邮政编码并返回与该邮政编码匹配的所有城市。 USPS 网站上的手动查找会执行此操作,而 Crate and Barrel 在其结账时会执行此操作。 USPS 的邮政编码
看起来 checkZip 函数是在用户的 zip 绑定(bind)到参数之前触发的。有没有更好的方法使用 Angular 工具来完成此任务?我想在用户输入正确的邮政编码后立即启动用户流程的下一步。 H
在 PostgreSQL 数据库中保存 ZipCode 值的正确列类型是什么? 最佳答案 我强烈反对这里提出的建议。 接受的答案接受非数字的东西。 问题是关于邮政编码,而不是邮政编码。 如果我们假设邮
是否可以获取使用 google maps api 找到的位置的邮政编码? 目前它返回经度和纬度,但不返回邮政编码。 我找到了这个邮政编码:http://www.census.gov/tiger/tms
我试图从邮政编码获取坐标,但出现错误 { "error_message" = "This IP, site or mobile application is not authorized to use
我要上课 Student(having instance variables private int rollno, String studentName, int age, Ad
我已经阅读了关于 stackoverflow 的几个答案,这些答案没有解决为三星 Galaxy 邮政编码显示数字键盘的问题。 iOS 将调出数字键盘,但 Samsung Galaxy 不会调出此代码的
我正在使用 R 传单包来创建美国的交互式 choropleth 网上有几个教程,我能够创建具有弹出窗口和缩放功能的交互式状态级别 map 。此外,我还能够使用弹出窗口再次创建单独的邮政编码级别 map
我已经阅读了很多关于此的帖子,但我无法让它发挥作用。我正在导入地址电子表格。邮政编码列包含 5 位邮政编码、9 位邮政编码和 5-4 个邮政编码(5 位数字、破折号和 4 位数字)的组合。 (抱歉,我
我知道这可能很简单,但是当我执行 #form.zipcode# 时,如何只从名为 zipcode 的表单字段中选择前 3 位数字 如果可能的话,我希望它在 cfml 中。 例如 03954 变成 03
我使用以下example来自谷歌地图文档,但我想在搜索城市时获取邮政编码。例如,如果我输入纽约,纽约,美国,我会得到除邮政编码之外的所有所需信息,是否也有机会获取此信息?目的是进行多选输入,并能够使用
我在这里找到了很多计算和一些 php 示例,大多数都在我的脑海中。 我找到了这个例子: SELECT b.zip_code, b.state, (3956 * (2 * ASIN(SQR
我是一名优秀的程序员,十分优秀!