We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
过去我用过这个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.
提供带有纬度/经度的商业邮政编码数据库。它们并不昂贵,也不是很大(好吧,如果你限制在美国,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.
这是您会找到的最好的免费邮政编码数据库: 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";
您可以尝试此 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
查看 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).
你对 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.
我多年来一直使用 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.