Class: ReverseGeocode
- Inherits:
-
Object
- Object
- ReverseGeocode
- Defined in:
- lib/reverse_geocode.rb
Overview
Defined Under Namespace
Classes: GeocodeError
Constant Summary collapse
- GOOGLE_URI =
"http://maps.google.com/maps/geo"
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Instance Attribute Summary collapse
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#long ⇒ Object
readonly
Returns the value of attribute long.
Instance Method Summary collapse
- #address ⇒ Object
- #city ⇒ Object
- #county ⇒ Object
-
#initialize(lat, long) ⇒ ReverseGeocode
constructor
Creates a new reverse geocode object.
-
#response ⇒ Object
The raw response hash from the reverse geocode request.
- #state ⇒ Object
- #street ⇒ Object
- #zip ⇒ Object
Constructor Details
#initialize(lat, long) ⇒ ReverseGeocode
Creates a new reverse geocode object.
34 35 36 37 |
# File 'lib/reverse_geocode.rb', line 34 def initialize(lat, long) raise ArgumentError, "Latitude and longitude required" unless lat && long @lat, @long = lat, long end |
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
31 32 33 |
# File 'lib/reverse_geocode.rb', line 31 def api_key @api_key end |
Instance Attribute Details
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
38 39 40 |
# File 'lib/reverse_geocode.rb', line 38 def lat @lat end |
#long ⇒ Object (readonly)
Returns the value of attribute long.
38 39 40 |
# File 'lib/reverse_geocode.rb', line 38 def long @long end |
Instance Method Details
#address ⇒ Object
45 46 47 |
# File 'lib/reverse_geocode.rb', line 45 def address @address ||= first_placemark/'address' end |
#city ⇒ Object
61 62 63 |
# File 'lib/reverse_geocode.rb', line 61 def city @city ||= (placemark_by_accuracy(4)/'AddressDetails'/'Country'/'AdministrativeArea'/'AddressLine').first end |
#county ⇒ Object
65 66 67 |
# File 'lib/reverse_geocode.rb', line 65 def county @county ||= (placemark_by_accuracy(3)/'AddressDetails'/'Country'/'AdministrativeArea'/'AddressLine').first end |
#response ⇒ Object
The raw response hash from the reverse geocode request
41 42 43 |
# File 'lib/reverse_geocode.rb', line 41 def response @response ||= handle_response end |
#state ⇒ Object
53 54 55 |
# File 'lib/reverse_geocode.rb', line 53 def state @state ||= first_administrative_area/'AdministrativeAreaName' end |
#street ⇒ Object
49 50 51 |
# File 'lib/reverse_geocode.rb', line 49 def street @street ||= first_administrative_area/'Thoroughfare'/'ThoroughfareName' end |
#zip ⇒ Object
57 58 59 |
# File 'lib/reverse_geocode.rb', line 57 def zip @zip ||= first_administrative_area/'PostalCode'/'PostalCodeNumber' end |