Best Zip Code Plugin for Ruby [closed]
Asked Answered
C

3

16

I need to find the city and state from a zip code. Does anyone know a good plugin/API that I can use to do this?

Capitulary answered 14/10, 2010 at 15:51 Comment(0)
K
19
gem install geokit

In IRB:

require 'geokit'
geo = GeoKit::Geocoders::MultiGeocoder.multi_geocoder('90210')
if geo.success
  geo.state # => CA
  geo.city  # => Beverly Hills
end
Koestler answered 14/10, 2010 at 20:0 Comment(2)
Most excellent catch! I forgot about geokit.Inchoation
github.com/geokit/geokitLindley
D
7

A more lightweight option is the Area gem.

require 'area'

'11211'.to_region #=> "Brooklyn, NY"
Dunham answered 28/6, 2012 at 0:49 Comment(5)
just implemented area, and gotta say -- its pretty awesome! much feeling to the api than geokit.Antemundane
If area covers your geocoding needs, its really a nice gem.Glenglencoe
Heh. A library that modifies a core class like String is not something I'd call "lightweight".Schema
"Lightweight" depends on your definition. The zipped download from Github is 682KB vs 138KB for Geokit - this is likely due to the csv files included. As far as ease of use and setup time though, I agree, it is much lighter weight. It being limited to US though, it's a little too lightweight for some requirements.Callow
Exactly what I needed.Pupil
I
0

See Jason's answer. It works nicely.


The problem is that the USPS doesn't allow bulk downloads of their zip-code lists unless you pay for it. Google's API, which is used in the gem mentioned by Splashlin, no longer seems to support the city and state, instead it now returns the area code:

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"}}

This page shows some ways you could roll your own. The sources of the data might not be current though:

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

Inchoation answered 14/10, 2010 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.