Class: GoogleGeocodings::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_geocodings/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = @api_key) ⇒ Client

Creates a new Client instance which proxies the requests to the certain classes

Parameters:

  • api_key (String) (defaults to: @api_key)

    The api key to use for the requests



9
10
11
# File 'lib/google_geocodings/client.rb', line 9

def initialize(api_key = @api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyString (readonly)

Returns the provided api key.

Returns:

  • (String)

    the provided api key



4
5
6
# File 'lib/google_geocodings/client.rb', line 4

def api_key
  @api_key
end

Instance Method Details

#geocode(address, options = {}) ⇒ Array<Geocoding>

geocode

see: developers.google.com/maps/documentation/geocoding/intro#geocoding NOTE: Not yet correspond to components param

Parameters:

  • address (String)
  • options (Hash) (defaults to: {})

    @option bounds [Hash]

    @bounds start_latitude [Float]
    @bounds start_longitude [Float]
    @bounds end_latitude [Float]
    @bounds end_longitude [Float]
    

    @option language [String] @option region [String]

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/google_geocodings/client.rb', line 27

def geocode(address, options = {})
  language   = options.delete(:language)
  region     = options.delete(:region)
  rectangle  = Rectangle.new(options.delete(:bounds))

  options = {
    key: api_key,
    address: address,
    language: language,
    region: region,
    bounds: rectangle.format,
  }
  request(:geocode, options)
end

#reverse_geocode(latitude, longitude, options = {}) ⇒ Array<Geocoding>

reverse geocode

see: developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding NOTE: Not yet correspond to components param

Parameters:

  • address (String)
  • options (Hash) (defaults to: {})

    @option bounds [Hash]

    @bounds start_latitude [Float]
    @bounds start_longitude [Float]
    @bounds end_latitude [Float]
    @bounds end_longitude [Float]
    

    @option language [String] @option region [String]

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/google_geocodings/client.rb', line 56

def reverse_geocode(latitude, longitude, options = {})
  language   = options.delete(:language)
  region     = options.delete(:region)
  rectangle  = Rectangle.new(options.delete(:bounds))

  options = {
    key: api_key,
    latlng: Location.new(latitude, longitude).format,
    language: language,
    region: region,
    bounds: rectangle.format,
  }
  request(:geocode, options)
end