使用Geocoder gem,使用advanced geocoding部分我似乎无法使其发挥作用。我基本上在Google Maps Documentation上取了每个地址组件类型并将其放在 Geocoder :: Result块中:
geocoded_by :street_address do |obj,results|
if geo = results.first
obj.route = geo.route
obj.intersection = geo.intersection
obj.political = geo.political
obj.country = geo.country
obj.administrative_area_level_1 = geo.administrative_area_level_1
obj.administrative_area_level_2 = geo.administrative_area_level_2
obj.administrative_area_level_3 = geo.administrative_area_level_3
obj.colloquial_area = geo.colloquial_area
obj.floor = geo.floor
obj.room = geo.room
end
end
after_validation :reverse_geocode
但是我收到了这个错误:
NoMethodError in StoresController#create
undefined method `route' for #<Geocoder::Result::Google:0x6939150>
如果我删除此对象,它只会转到下一个对象,例如intersection
。
这里有什么问题?
答案 0 :(得分:4)
来自API文档http://rdoc.info/github/alexreisner/geocoder/master/Geocoder/Result/Google
- (Object) address_components_of_type(type)
Get address components of a given type. Valid types are defined in Google's Geocoding API documentation and include (among others):
:street_number
:locality
:neighborhood
:route
:postal_code
因此,对于路线示例,您需要致电geo.address_components_of_type(:route)