user4827489
user4827489

Reputation:

How to use gem 'geokit' to validate zipcode with respect to city and state in rails4?

I want to use gem 'geokit' as my requirement is to validate my zipcode on the basis of city and province/state. Please guide me how to use it. I had tried my own validation in my model but it don't work for me. Please help me out. I got stuck with this issue from last 15 days not getting a way.

Upvotes: 0

Views: 805

Answers (2)

Abdul Baig
Abdul Baig

Reputation: 3721

Here is what you need:

require 'openssl'
require 'geokit'

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

Or you can use:

A more lightweight option is the Area gem.

require 'area'

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

Upvotes: 1

Dinshaw Raje
Dinshaw Raje

Reputation: 963

This works for me :

require 'openssl'
require 'geokit'

geo = GeoKit::Geocoders::MultiGeocoder.geocode('90210')
geo.city
geo.state

Upvotes: 1

Related Questions