Ruby-on-rails 免费城市/州/邮政编码到纬度/经度数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4894104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Free City/State/Zipcode to Latitude/Longitude Database?
提问by Lance Pollard
Is there a standard database of records mapping city/state/zip to lat/lng? I found this database, and the USPS has a simple (no lat/lng) API, but is there another recommended alternative?
是否有将城市/州/邮编映射到纬度/经纬度的标准记录数据库?我找到了这个数据库,并且USPS 有一个简单的(无纬度/经度)API,但是还有其他推荐的替代方案吗?
Update: Found this too: http://www.geopostcodes.com/
更新:也发现了这个:http: //www.geopostcodes.com/
回答by Andrew - OpenGeoCode
Just a small note. Most of these 3rd party city/state/zip to lat/lng databases are based on the US Census Tiger data. Start with the Census 2000, the zip code data was replaced with ZCTA - which is an approximation of zipcodes. Here's an explanation from the Census site (from 2011):
只是一个小笔记。这些 3rd 方城市/州/邮编到纬度/经纬度数据库中的大多数都基于美国人口普查老虎数据。从 2000 年人口普查开始,邮政编码数据被替换为 ZCTA - 这是邮政编码的近似值。以下是人口普查网站的解释(从 2011 年开始):
ZIP Code Tabulation Areas (ZCTAs?) are a new statistical entity developed by the U.S. Census Bureau for tabulating summary statistics from Census 2000. This new entity was developed to overcome the difficulties in precisely defining the land area covered by each ZIP Code?. Defining the extent of an area is necessary in order to accurately tabulate census data for that area.
ZIP Code Tabulation Areas (ZCTA?) 是美国人口普查局开发的一个新的统计实体,用于对 2000 年人口普查的汇总统计数据进行制表。开发这个新实体是为了克服精确定义每个 ZIP Code? 所涵盖的土地面积的困难。定义一个区域的范围是必要的,以便准确地将该区域的人口普查数据制成表格。
ZCTAs are generalized area representations of U.S. Postal Service (USPS) ZIP Code service areas. Simply put, each one is built by aggregating the Census 2000 blocks, whose addresses use a given ZIP Code, into a ZCTA which gets that ZIP Code assigned as its ZCTA code. They represent the majority USPS five-digit ZIP Code found in a given area. For those areas where it is difficult to determine the prevailing five-digit ZIP Code, the higher-level three-digit ZIP Code is used for the ZCTA code. For more information, please refer to the ZCTA (FAQ) Frequently Asked Questions Web page.
ZCTA 是美国邮政服务 (USPS) 邮政编码服务区域的广义区域表示。简而言之,每个区块都是通过将地址使用给定邮政编码的 Census 2000 块聚合到 ZCTA 中来构建的,ZCTA 将该邮政编码分配为其 ZCTA 代码。它们代表在给定区域中发现的大多数 USPS 五位数邮政编码。对于难以确定现行五位数邮政编码的地区,ZCTA 代码使用较高级别的三位数邮政编码。有关更多信息,请参阅 ZCTA (FAQ) 常见问题解答网页。
The link below is an updated explanation (2013):
下面的链接是更新的解释(2013):
http://www.census.gov/geo/reference/zctas.html
http://www.census.gov/geo/reference/zctas.html
The OpenGeoCode.Org team
OpenGeoCode.Org 团队
ADDED 12/17/13: Our (FREE) state/city/zip dataset (CSV) can be found at the link below. It is derived from public domain "government" datasets:
2013 年 12 月 17 日添加:我们的(免费)州/城市/邮编数据集 (CSV) 可在以下链接中找到。它源自公共领域的“政府”数据集:
回答by Jason
Google offers this as a lookup. Can you do ajax calls from your app?
谷歌将此作为查找提供。你可以从你的应用程序中调用 ajax 吗?
It's called webservices. http://code.google.com/apis/maps/documentation/webservices/index.html
它被称为网络服务。 http://code.google.com/apis/maps/documentation/webservices/index.html
You'd want to use the Google Geocoding api. It's simple to use, make a call to this url: http://maps.googleapis.com/maps/api/geocode/json?address=sydney&sensor=false
您想使用 Google Geocoding api。使用起来很简单,调用这个网址:http: //maps.googleapis.com/maps/api/geocode/json?address= sydney&sensor= false
Change "address=" to whatever you need (ie the city state and zip code)
将“地址=”更改为您需要的任何内容(即城市州和邮政编码)
It can also reply in xml. just change json to xml http://code.google.com/apis/maps/documentation/geocoding/
它也可以在 xml 中回复。只需将 json 更改为 xml http://code.google.com/apis/maps/documentation/geocoding/
Example Result
示例结果
{
"status": "OK",
"results": [ {
"types": [ "locality", "political" ],
"formatted_address": "Sydney New South Wales, Australia",
"address_components": [ {
"long_name": "Sydney",
"short_name": "Sydney",
"types": [ "locality", "political" ]
}, {
"long_name": "New South Wales",
"short_name": "New South Wales",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "Australia",
"short_name": "AU",
"types": [ "country", "political" ]
} ],
"geometry": {
"location": {
"lat": -33.8689009,
"lng": 151.2070914
},
"location_type": "APPROXIMATE",
"viewport": {
"southwest": {
"lat": -34.1648540,
"lng": 150.6948538
},
"northeast": {
"lat": -33.5719182,
"lng": 151.7193290
}
},
"bounds": {
"southwest": {
"lat": -34.1692489,
"lng": 150.5022290
},
"northeast": {
"lat": -33.4245980,
"lng": 151.3426361
}
}
}
} ]
}
Then all you need to do is open up results[0].geometry.location.lat, and results[0].geometry.location.lng
然后你需要做的就是打开results[0].geometry.location.lat,然后results[0].geometry.location.lng
回答by puddleglum
[EDIT 8/3/2015]The free non-commercial ZIP Code database I mentioned below has moved to softwaretools.com. Note: greatdata.comstill has the premium ZIP Code data for enterprises.
[编辑 8/3/2015]我在下面提到的免费非商业邮政编码数据库已移至softwaretools.com。注意:greatdata.com仍然为企业提供优质的邮政编码数据。
Just a small note. Most of these 3rd party city/state/zip to lat/lng databases are based on the US Census Tiger data. [Andrew]
只是一个小笔记。这些 3rd 方城市/州/邮编到纬度/经纬度数据库中的大多数都基于美国人口普查老虎数据。[安德鲁]
I'm a developer for a commercial ZIP Code Database company (GreatData). For low-end data, Andrew's recommendation is correct and if you know your way around census data, it's pretty easy to get it. Just know it may initially take some hours to get it right. If you prefer not to do the work yourself, you can get our free/non-commercial version here(it's pretty much what Andrew is suggesting with minor enhancements. It's updated every couple months).
我是一家商业邮政编码数据库公司 (GreatData) 的开发人员。对于低端数据,Andrew 的建议是正确的,如果您了解人口普查数据,则很容易获得。只知道最初可能需要几个小时才能把它做好。如果您不想自己完成这项工作,您可以在此处获取我们的免费/非商业版本(这几乎是 Andrew 建议的内容,并进行了小幅改进。每隔几个月更新一次)。
For a really good explanation on what is missing in it (and more importantly, what's missing in most all low-end ZIP Code data that is based on census ZCTA data) versus a commercial grade, see here.
有关其中缺少的内容(更重要的是,基于人口普查 ZCTA 数据的大多数低端邮政编码数据中缺少的内容)与商业等级的真正好解释,请参见此处。
ps - regarding suggestions to use Google's API, I see this suggested a lot but unless you're displaying it in a google map, this violates Googles TOS. Specifically: "The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited." You'll find StackOverFlow has several threads on those who's sites have been blocked.
ps - 关于使用谷歌 API 的建议,我看到很多建议,但除非你在谷歌地图中显示它,否则这违反了谷歌的 TOS。具体来说:“地理编码 API只能与 Google 地图结合使用;禁止在地图上不显示地理编码结果。” 你会发现 StackOverFlow 有几个关于那些站点被阻止的线程。
Hope this is beneficial
希望这是有益的
回答by Kevin P.
This is an old thread, but I was looking for the same information recently and also came across this free database:
这是一个旧线程,但我最近正在寻找相同的信息,并且还遇到了这个免费数据库:
回答by Rob Sedgwick
If you have a small number of US cities you can easily build up your own database from Google which gives you the co-ordinates straight on the search page without the need to follow any links, e.g. type:
如果您拥有少量美国城市,您可以轻松地从 Google 建立自己的数据库,该数据库直接在搜索页面上为您提供坐标,而无需点击任何链接,例如输入:
chicago illinois longitude latitude
芝加哥伊利诺伊州经度纬度

