Reputation: 27192
With the Geocoder gem, using the advanced geocoding section I can't seem to get it to work. I basically took every Address Component Type on the Google Maps Documentation and put it inside of the Geocoder::Result block:
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
But I get this error:
NoMethodError in StoresController#create
undefined method `route' for #<Geocoder::Result::Google:0x6939150>
If I remove it this object it just goes to the next one, such as intersection
.
What is the issue here?
Upvotes: 1
Views: 858
Reputation: 21548
From the API documentation 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
So for the route example you need to call geo.address_components_of_type(:route)
Upvotes: 4