1

使用Geocoder gem,使用高级地理编码部分,我似乎无法让它工作。我基本上把谷歌地图文档上的每个地址组件类型都放在了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.

这里有什么问题?

4

1 回答 1

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)

于 2012-06-03T01:51:12.703 回答