apneadiving/Google-Maps-for-Rails — Issue #154: Easier access to geocoder result
Author: miligraf
Created: 2012-02-24 20:28:00+00:00
State: open

I don't know if this is worth a fork, but adding this to lib/gmaps4rails/geocoding.rb will give easier access to the geocoder results such as city, county, province, country and postal code:

def Gmaps4rails.handle_geocoding_response(request, response, raw)
...
parse["results"].each do |result|
array << {
:lat => result["geometry"]["location"]["lat"],
...
:city => result["address_components"].detect{|ac| ac["types"].include?("locality")}["long_name"],
:county => result["address_components"].detect{|ac| ac["types"].include?("administrative_area_level_2")}["long_name"],
:province => result["address_components"].detect{|ac| ac["types"].include?("administrative_area_level_1")}["long_name"],
:country => result["address_components"].detect{|ac| ac["types"].include?("country")}["long_name"],
:postal_code => result["address_components"].detect{|ac| ac["types"].include?("postal_code")}["long_name"]
}
...
end