Class: Geocoder::Result::Google
- Inherits:
-
Base
- Object
- Base
- Geocoder::Result::Google
show all
- Defined in:
- lib/geocoder/results/google.rb
Instance Attribute Summary
Attributes inherited from Base
#data
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #latitude, #longitude
Instance Method Details
#address(format = :full) ⇒ Object
10
11
12
|
# File 'lib/geocoder/results/google.rb', line 10
def address(format = :full)
formatted_address
end
|
#address_components ⇒ Object
50
51
52
|
# File 'lib/geocoder/results/google.rb', line 50
def address_components
@data['address_components']
end
|
#address_components_of_type(type) ⇒ Object
Get address components of a given type. Valid types are defined in Google’s Geocoding API documentation and include (among others):
:street_number
:locality
:neighborhood
:route
:postal_code
64
65
66
|
# File 'lib/geocoder/results/google.rb', line 64
def address_components_of_type(type)
address_components.select{ |c| c['types'].include?(type.to_s) }
end
|
#city ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/geocoder/results/google.rb', line 14
def city
fields = [:locality, :sublocality, :administrative_area_level_3,
:administrative_area_level_2, :administrative_area_level_1]
fields.each do |f|
if entity = address_components_of_type(f).first
return entity['long_name']
end
end
end
|
#coordinates ⇒ Object
6
7
8
|
# File 'lib/geocoder/results/google.rb', line 6
def coordinates
['lat', 'lng'].map{ |i| geometry['location'][i] }
end
|
#country ⇒ Object
24
25
26
27
28
|
# File 'lib/geocoder/results/google.rb', line 24
def country
if country = address_components_of_type(:country).first
country['long_name']
end
end
|
#country_code ⇒ Object
30
31
32
33
34
|
# File 'lib/geocoder/results/google.rb', line 30
def country_code
if country = address_components_of_type(:country).first
country['short_name']
end
end
|
46
47
48
|
# File 'lib/geocoder/results/google.rb', line 46
def formatted_address
@data['formatted_address']
end
|
#geometry ⇒ Object
68
69
70
|
# File 'lib/geocoder/results/google.rb', line 68
def geometry
@data['geometry']
end
|
#postal_code ⇒ Object
36
37
38
39
40
|
# File 'lib/geocoder/results/google.rb', line 36
def postal_code
if postal = address_components_of_type(:postal_code).first
postal['long_name']
end
end
|
#types ⇒ Object
42
43
44
|
# File 'lib/geocoder/results/google.rb', line 42
def types
@data['types']
end
|