使用 Google API 根据城市和州生成邮政编码
有没有办法根据表单中的城市/州输入进行邮政编码查找?我认为 Google 地理编码 API 可能是正确的方向。有什么想法吗?我有一个基于 Wordpress 构建的网站,因此代码必须使用 PHP。提前致谢。
Would there be a way to do a zip code lookup based on City/State input in a form? I'm thinking the Google geocode API might be the right direction. Any thoughts? I have a site built on Wordpress so the code would have to utilize PHP. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
YQL 可以做这样的事情:
返回:
YQL 控制台
有关于如何在 PHP 和 Javascript 在其网站上。
YQL can do things like this:
returns:
YQL Console
There are examples on there on how to implement queries like this in both PHP and Javascript on their site.
地理编码是您查找地址坐标的地方。是的,您可以对城市、州进行地理编码,但这将为您提供城市的中心(由地理编码器的内部数据库定义 - 通常是质心或“市政厅”。
大多数城市都有多个邮政编码:您想要所有这些吗?
同样,邮政编码可能包含多个城市 - 特别是在邮政编码可能很大的农村地区,而城市就是其他国家所谓的“村庄”和“小村庄”,
因此您最好的选择可能是获取数据库。周围可能有一些免费的(我想到了 Geonames,但我认为它没有邮政编码),但您最终可能不得不购买一个。
Geocoding is where you find the coordinates of an address. Yes you could geocode a city,state but this would give you he center of the city (as defined by the geocoder's internal database - typically a centroid or 'city hall'.
Most cities have multiple zip codes: Do you want all of these?
Similarly a zip code could contain multiple cities - especially in rural areas where zip codes can be large and cities are what other countries would call 'villages' and 'hamlets'
So you best bet is probably to get a database. There might be some free ones around (Geonames comes to mind but I don't think it has zip codes), but you might end up having to buy one.
首先是关于 Google API 的说明:请注意 Google 的 TOS,这样您就不会不要像其他人那样走一条浪费的路(有时是在不知不觉中)。具体来说:“注意:地理编码 API 只能与 Google 地图结合使用;禁止在地图上显示地理编码结果。”。
如果您的项目不是任务,您最好的选择是获得免费邮政编码数据库 -批判的;否则,您可能需要一个良好的商业级数据库。只需谷歌“商业级邮政编码数据库”即可。
另外,请参阅一个很好的堆栈溢出线程< /a> 关于这个主题。
First a note on the Google API: be aware of Google's TOS so you don't take a wasted path as others have done (sometimes unknowingly). Specifically: "Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.".
Your best bet is to get a free zip code database if your project is not mission-critical; otherwise, you'll probably need a good commercial-grade database. Just google "commercial grade zip code database".
Also, see a good stack-overflow thread about this topic.