简体   繁体   中英

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.

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"

This works for me :

require 'openssl'
require 'geokit'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM