PHP 中的邮政编码定位器

发布于 2024-11-15 07:27:05 字数 1539 浏览 3 评论 0原文

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

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

发布评论

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

评论(7

Hello爱情风 2024-11-22 07:27:05

过去我用过这个PHP 类。虽然我没有广泛使用它,但它在邮政编码查找和距离方面满足了我的需要。

In the past I have used this PHP class. While I haven't used it very extensively, it did what I needed it to do in terms of Zip Code lookup and distance.

戴着白色围巾的女孩 2024-11-22 07:27:05

提供带有纬度/经度的商业邮政编码数据库。它们并不昂贵,也不是很大(好吧,如果你限制在美国,40K 小记录左右)。我过去在 zip-finder.com 上运气不错,但重要的警告...一旦您开始维护自己的邮政编码表,您将需要使其与 USPS 对邮政编码所做的任何操作保持同步时间。他们做的一件真正令人恼火的事情是删除邮政编码。

也就是说,计算距离非常简单,但每个邮政编码只能得到一个纬度/经度点(或多或少是区域的质心)。对于较大的邮政编码,您的距离精度可能会有一英里或更多的偏差,因此请注意这一点。

Commercial zip code databases with Lat/Long are available. They are not expensive and are not large (well, if you restrict to USA, 40K small records or so). I have had good luck with zip-finder.com in the past, but important caveat... once you begin maintaining your own zip code table(s), you will need to keep it in sync with whatever the USPS does with zipcodes over time. One really irritating thing they do is remove zipcodes.

That said, calculating distance is pretty trivial, but you only get one lat/long point per zipcode (more or less the centroid of area). For a large zipcode, your distance accuracy can have a mile or more of slop in it, so be aware of that.

长途伴 2024-11-22 07:27:05

这是您会找到的最好的免费邮政编码数据库: http://federalgovernmentzipcodes.us/

如果您不这样做,它就可以正常工作不需要超级准确的经纬度。不幸的是,经纬度并不是那么准确,不是因为有两位小数,而是因为它们有点偏差。

重新设计了这个数据库,使经纬度更加准确。

我通过点击谷歌地图maps.googleapis.com/maps/api/geocode/json?address="zip code city state";

This is the best free zip code database you will find: http://federalgovernmentzipcodes.us/

It works fine if you don't need super accurate lat,lng. Unfortunately the lat,lng are not that accurate, not because of the two decimal places - but rather because they are simply a bit off.

I reworked this database to make the lat,lng more accurate by hitting google maps

maps.googleapis.com/maps/api/geocode/json?address="zip code city state";

是你 2024-11-22 07:27:05

您可以尝试此 API

http://ws.geonames.org/postalCodeSearch?postalcode=10033

也给出带有纬度和经度的结果

You can try this API

http://ws.geonames.org/postalCodeSearch?postalcode=10033

Gives out results with lat and long too

Bonjour°[大白 2024-11-22 07:27:05

查看 PHP-ZipCode-Class。您可以使其适应任意数量的邮政编码数据库。就我个人而言,我会选择商业数据库,因为免费的数据库很容易就会过时。相信我。多年来我一直试图在一个高流量的电子商务网站上维护一个免费数据库。购买商业数据库会便宜很多。如果您确实坚持使用免费数据库,这里有一些我知道的(但尚未尝试过)。

Check out PHP-ZipCode-Class. You can adapt it to any number of zip code databases. Personally, I would go with a commercial database as the free ones can easily get outdated. Trust me on that. I tried to maintain a free database on a high traffic e-commerce site for years. Would have been a LOT CHEAPER to just buy a commercial database. If you really insist on a free database, here are a couple that I know of (but have not tried).

最单纯的乌龟 2024-11-22 07:27:05

你对 api 限制的看法是正确的。 Bing 也是如此(尽管他们的 api 非常好)。

如果您使用数据库...
虽然需要做一些工作,但您可以从美国人口普查老虎数据免费获得它 - 这是大多数低端第三方邮政编码数据库所基于的。只需知道,在 2000 年,他们用 ZCTA 取代了邮政编码(与邮政编码类似,但不准确)。我添加了下面的链接,其中包含来自人口普查网站的 ZCTA 解释:http:// /www.census.gov/geo/ZCTA/zcta.html

其他需要考虑的事项:大多数纬度和经度质心基于几何计算 - 这意味着它们可能落在林地中间,大无人居住的湖泊、公园(例如中央公园)。我不确定您的需求是什么,但这可能适合您。如果您需要基于人口的中心,您可能需要商业数据(请参阅http://greatdata.com/ zip-codes-lat-long 单击顶部的“更多详细信息”选项卡以获取有关此主题的说明)。

另外,确定您是否只需要每个邮政编码的主要城市(一对一关系 - 通常超过 40,000 条记录),或者如果邮政编码边界涵盖多个城市,则需要将每个城市列为单独的记录(~ 57,000 条记录)。大多数定位器和地址验证实用程序都需要后者。

You're correct about the api limitations. It is true with Bing as well (although their api is pretty good).

If you go with a database...
Although it takes a little work, you can get it free from the US Census Tiger Data - which is what most low-end 3rd party ZIP Code database are based on. Just know that in 2000, they replaced the ZIP Code with ZCTA (which is ZIP Code like, but not exact). I’ve included the link below which has an explanation of ZCTA from the census site: http://www.census.gov/geo/ZCTA/zcta.html

Other things to consider: most latitude and longitude centroids are based on geometric calculations- meaning they could fall in the middle of forestry land, large lakes, parks (e.g. Central Park) where no people live. I’m not sure what your needs are but that may be fine for you. If you need population based centers, you will probably need commercial data (see http://greatdata.com/zip-codes-lat-long click the ‘more details’ tab at the top for an explanation of this topic).

Also, determine if you only need the major city for each ZIP Code (one-to-one relationship – normally 40,000+ records) or if a ZIP Code boundary covers more than one city, you need each city listed as a separate record (~57,000 records). Most locators and address validation utilities need the latter.

半步萧音过轻尘 2024-11-22 07:27:05

我多年来一直使用 http://zip-info.com/ 中的邮政编码数据库。它每季度更新一次(非常重要)并且非常准确。该数据库的价格约为 50 美元,我每年购买两次更新。

美国有大约 54,000 个 5 位数邮政编码 - 因此任何好的数据库都会很大 - 如果您想减少数据,只需删除不需要的数据字段(将其限制为 zip/lat/lon)存储(尽管这是最小的节省)。正如 Rob 所说,距离计算很容易完成 - 只需寻找一个可以作为起始点进行大圆计算的脚本即可。

I've been using the zip-code database from http://zip-info.com/ for many years. It's updated every quarter (very important) and is very accurate. The database is about $50 and I purchase an update twice a year.

There are something like 54,000 5 digit zip codes in the US - so any good database is going to be large - just strip out the data fields you don't need (limit it to zip/lat/lon) if you want to reduce data storage (though it's minimal savings). As Rob said, distance calcs are easy to do - just look for a script that does great circle calculations as a staring point.

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