Class: Google::Geo::Address

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/google/geo.rb

Overview

Represents locations returned in response to geocoding queries.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#fetch, #fetch_accuracy

Constructor Details

#initialize(placemark, query) ⇒ Address

:nodoc



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/google/geo.rb', line 117

def initialize(placemark, query) #:nodoc
  @xml   = placemark
  @query = query
  
  {
    :@street       => :ThoroughfareName,
    :@city         => :LocalityName,
    :@zip          => :PostalCodeNumber,
    :@county       => :SubAdministrativeAreaName,
    :@state        => :AdministrativeAreaName,
    :@country      => :CountryNameCode,
    
    :@full_address => :address
  }.each do |attribute, element|
    instance_variable_set(attribute, (fetch(element) rescue nil))
  end
  
  @longitude, @latitude, @elevation = @coordinates = fetch(:coordinates).split(',').map { |x| x.to_f }
  
  @accuracy = fetch_accuracy
end

Instance Attribute Details

#accuracyObject (readonly)

An integer, Google’s rating of the accuracy of the supplied address.



108
109
110
# File 'lib/google/geo.rb', line 108

def accuracy
  @accuracy
end

#cityObject (readonly) Also known as: locality

Returns the value of attribute city.



78
79
80
# File 'lib/google/geo.rb', line 78

def city
  @city
end

#coordinatesObject (readonly)

An array containing the standard three elements of a coordinate triple: latitude, longitude, elevation.



94
95
96
# File 'lib/google/geo.rb', line 94

def coordinates
  @coordinates
end

#countryObject (readonly) Also known as: country_code

Returns the value of attribute country.



90
91
92
# File 'lib/google/geo.rb', line 90

def country
  @country
end

#countyObject (readonly) Also known as: subadministrative_area

Returns the value of attribute county.



84
85
86
# File 'lib/google/geo.rb', line 84

def county
  @county
end

#elevationObject (readonly)

A float, the standard third element of a coordinate triple.



105
106
107
# File 'lib/google/geo.rb', line 105

def elevation
  @elevation
end

#full_addressObject (readonly) Also known as: to_s

All address attributes as one string, formatted by the service.



111
112
113
# File 'lib/google/geo.rb', line 111

def full_address
  @full_address
end

#latitudeObject (readonly) Also known as: lat

A float, the standard second element of a coordinate triple.



101
102
103
# File 'lib/google/geo.rb', line 101

def latitude
  @latitude
end

#longitudeObject (readonly) Also known as: lng

A float, the standard first element of a coordinate triple.



97
98
99
# File 'lib/google/geo.rb', line 97

def longitude
  @longitude
end

#queryObject (readonly)

The address query sent to the service. i.e. The user input.



115
116
117
# File 'lib/google/geo.rb', line 115

def query
  @query
end

#stateObject (readonly) Also known as: administrative_area

Returns the value of attribute state.



87
88
89
# File 'lib/google/geo.rb', line 87

def state
  @state
end

#streetObject (readonly) Also known as: thoroughfare

Returns the value of attribute street.



75
76
77
# File 'lib/google/geo.rb', line 75

def street
  @street
end

#zipObject (readonly) Also known as: postal_code

Returns the value of attribute zip.



81
82
83
# File 'lib/google/geo.rb', line 81

def zip
  @zip
end