4

有没有办法根据表单中的城市/州输入进行邮政编码查找?我认为 Google 地理编码 API 可能是正确的方向。有什么想法吗?我有一个基于 Wordpress 构建的网站,因此代码必须使用 PHP。提前致谢。

4

3 回答 3

1

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.

于 2010-11-11T20:43:02.073 回答
1

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中实现这样的查询的示例。

于 2011-03-16T06:54:16.007 回答
0

首先是关于 Google API 的说明:请注意Google 的 TOS,这样您就不会像其他人那样(有时是在不知不觉中)走上浪费的道路。具体来说:“注意:Geocoding API 只能与 Google 地图一起使用;禁止地理编码结果而不显示在地图上。”。

如果你的项目不是关键任务,你最好的选择是获得一个免费的邮政编码数据库;否则,您可能需要一个良好的商业级数据库。只需谷歌“商业级邮政编码数据库”。

另外,请参阅有关此主题的良好堆栈溢出线程。

于 2012-12-05T22:25:12.717 回答