Class: Gmaps4rails::Places

Inherits:
Object
  • Object
show all
Includes:
BaseNetMethods
Defined in:
lib/gmaps4rails/api_wrappers/places.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseNetMethods

#base_url, #checked_google_response, #parsed_response, #response, #valid_parsed_response?, #valid_response?

Constructor Details

#initialize(lat, lng, options = {}) ⇒ Places

Returns a new instance of Places.



10
11
12
13
14
15
16
17
18
19
# File 'lib/gmaps4rails/api_wrappers/places.rb', line 10

def initialize(lat, lng, options = {})
  @lat, @lng = lat, lng
  raise_invalid     unless valid_position?
  raise_missing_key unless options[:key]
  options[:radius]  ||= 7500
  options[:lang]    ||= "en"
  options[:raw]     ||= false
  options[:protocol]||= "http"
  @options = OpenStruct.new options
end

Instance Attribute Details

#latObject (readonly)

Returns the value of attribute lat.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/places.rb', line 7

def lat
  @lat
end

#lngObject (readonly)

Returns the value of attribute lng.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/places.rb', line 7

def lng
  @lng
end

Instance Method Details

#getObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gmaps4rails/api_wrappers/places.rb', line 21

def get
  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"],
               :name      => result["name"],
               :reference => result["reference"],
               :vicinity  => result["vicinity"],
               :full_data => result
              }
    end
  end
end