Ruby最佳邮政编码插件

我需要从邮政编码中找到城市和州。 有谁知道我可以用来做这个的好插件/ API?

gem install geokit 

在IRB:

 require 'geokit' geo = GeoKit::Geocoders::MultiGeocoder.multi_geocoder('90210') if geo.success geo.state # => CA geo.city # => Beverly Hills end 

一个更轻量级的选项是Area gem 。

 require 'area' '11211'.to_region #=> "Brooklyn, NY" 

见杰森的回答。 它工作得很好。


问题是USPS不允许批量下载其邮政编码列表,除非您付费。 Google的API在Splashlin提到的gem中使用,似乎不再支持城市和州,而是现在返回区号:

 require 'open-uri' require 'json' json = JSON::parse(open('http://maps.google.com/maps/geo?q=852581').read) puts json # >> {"name"=>"852581", "Status"=>{"code"=>602, "request"=>"geocode"}} 

此页面显示了您可以自行推送的一些方法。 尽管如此,数据来源可能不是最新的:

http://www.ruby-forum.com/topic/48815