Class: Google::Geo

Inherits:
Object
  • Object
show all
Defined in:
lib/google/geo.rb,
lib/google/geo/params.rb,
lib/google/geo/parser.rb,
lib/google/geo/address.rb,
lib/google/geo/response.rb,
lib/google/geo/address/street_view.rb

Overview

Please see README for usage examples.

Defined Under Namespace

Modules: Parser Classes: Address, AddressError, BadRequestError, Error, InvalidMapKeyError, MapKeyError, MissingAddressError, Params, Response, ServerError, TooManyQueriesError, UnavailableAddressError, UnknownAddressError, UnknownError

Constant Summary collapse

CHARSET =

Google’s XML files state that they are utf-8 encoded which is not true. Because they state this explicitly, I see no need to let users set another charset.

"utf-8"
DEFAULT_LANGUAGE =
"en"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, language = DEFAULT_LANGUAGE) ⇒ Geo

Returns a new instance of Geo.



23
24
25
26
# File 'lib/google/geo.rb', line 23

def initialize(key, language = DEFAULT_LANGUAGE)
  @key      = key
  @language = language
end

Instance Attribute Details

#keyObject

API key provided by Google allowing access to the Geocode API



10
11
12
# File 'lib/google/geo.rb', line 10

def key
  @key
end

#languageObject

API key provided by Google allowing access to the Geocode API



10
11
12
# File 'lib/google/geo.rb', line 10

def language
  @language
end

#last_responseObject (readonly)

The last response received after a :locate call



13
14
15
# File 'lib/google/geo.rb', line 13

def last_response
  @last_response
end

Instance Method Details

#charsetObject



19
# File 'lib/google/geo.rb', line 19

def charset; CHARSET; end

#locate(*params) ⇒ Object

>> geo.locate “1600 Pennsylvania Ave”

# reverse locate
>> geo.locate 33.998671, -118.075926

Returns an array of Address objects, each with accessors for all the components of a location.



35
36
37
38
# File 'lib/google/geo.rb', line 35

def locate(*params)
  @last_response = Response.new(self, Params.new(self, *params))
  @last_response.addresses
end