[英]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 . 我想使用gem 'geokit'
因为我的要求是根据城市和省/州来验证我的邮政编码 。 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. 从最近15天开始,我就一直陷在这个问题上,却束手无策。
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 . 一个更轻便的选择是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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.