Class: Gmaps4rails::Geocoder
- Inherits:
-
Object
- Object
- Gmaps4rails::Geocoder
- Includes:
- BaseNetMethods
- Defined in:
- lib/gmaps4rails/api_wrappers/geocoder.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#get_coordinates ⇒ Object
returns an array of hashes with the following keys: - lat: mandatory for acts_as_gmappable - lng: mandatory for acts_as_gmappable - matched_address: facultative - bounds: facultative - full_data: facultative.
-
#initialize(address, options = {}) ⇒ Geocoder
constructor
A new instance of Geocoder.
Methods included from BaseNetMethods
#base_url, #checked_google_response, #get_response, #parsed_response, #response, #valid_parsed_response?, #valid_response?
Constructor Details
#initialize(address, options = {}) ⇒ Geocoder
Returns a new instance of Geocoder.
8 9 10 11 12 13 14 15 |
# File 'lib/gmaps4rails/api_wrappers/geocoder.rb', line 8 def initialize(address, = {}) raise Gmaps4rails::GeocodeInvalidQuery, "You must provide an address" if address.empty? @address = address @language = [:language] || "en" @raw = [:raw] || false @protocol = [:protocol] || "http" end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/gmaps4rails/api_wrappers/geocoder.rb', line 6 def address @address end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
6 7 8 |
# File 'lib/gmaps4rails/api_wrappers/geocoder.rb', line 6 def language @language end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/gmaps4rails/api_wrappers/geocoder.rb', line 6 def protocol @protocol end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/gmaps4rails/api_wrappers/geocoder.rb', line 6 def raw @raw end |
Instance Method Details
#get_coordinates ⇒ Object
returns an array of hashes with the following keys:
-
lat: mandatory for acts_as_gmappable
-
lng: mandatory for acts_as_gmappable
-
matched_address: facultative
-
bounds: facultative
-
full_data: facultative
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gmaps4rails/api_wrappers/geocoder.rb', line 23 def get_coordinates checked_google_response do return parsed_response if raw parsed_response["results"].inject([]) do |memo, result| memo << { :lat => result["geometry"]["location"]["lat"], :lng => result["geometry"]["location"]["lng"], :matched_address => result["formatted_address"], :bounds => result["geometry"]["bounds"], :full_data => result } end end end |