使用 Google API 根据城市和州生成邮政编码

发布于 2024-10-02 12:29:46 字数 110 浏览 7 评论 0原文

有没有办法根据表单中的城市/州输入进行邮政编码查找?我认为 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 技术交流群。

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

发布评论

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

评论(3

关于从前 2024-10-09 12:29:47

YQL 可以做这样的事情:

select  name from geo.places.children where parent_woeid in (select woeid from geo.places where text="sunnyvale, usa" limit 1) AND placetype = 11

返回:

{
 "query": {
  "count": 6,
  "created": "2011-03-16T06:49:09Z",
  "lang": "en-US",
  "results": {
   "place": [
    {
     "name": "94086"
    },
    {
     "name": "94087"
    },
    {
     "name": "94088"
    },
    {
     "name": "94089"
    },
    {
     "name": "94090"
    },
    {
     "name": "94085"
    }
   ]
  }
 }
}

YQL 控制台

有关于如何在 PHPJavascript 在其网站上。

YQL can do things like this:

select  name from geo.places.children where parent_woeid in (select woeid from geo.places where text="sunnyvale, usa" limit 1) AND placetype = 11

returns:

{
 "query": {
  "count": 6,
  "created": "2011-03-16T06:49:09Z",
  "lang": "en-US",
  "results": {
   "place": [
    {
     "name": "94086"
    },
    {
     "name": "94087"
    },
    {
     "name": "94088"
    },
    {
     "name": "94089"
    },
    {
     "name": "94090"
    },
    {
     "name": "94085"
    }
   ]
  }
 }
}

YQL Console

There are examples on there on how to implement queries like this in both PHP and Javascript on their site.

好倦 2024-10-09 12:29:47

地理编码是您查找地址坐标的地方。是的,您可以对城市、州进行地理编码,但这将为您提供城市的中心(由地理编码器的内部数据库定义 - 通常是质心或“市政厅”。

大多数城市都有多个邮政编码:您想要所有这些吗?
同样,邮政编码可能包含多个城市 - 特别是在邮政编码可能很大的农村地区,而城市就是其他国家所谓的“村庄”和“小村庄”,

因此您最好的选择可能是获取数据库。周围可能有一些免费的(我想到了 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.

云柯 2024-10-09 12:29:47

首先是关于 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.

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