Class: Geocoder::Result::Amap
- Inherits:
-
Base
- Object
- Base
- Geocoder::Result::Amap
show all
- Defined in:
- lib/geocoder/results/amap.rb
Instance Attribute Summary
Attributes inherited from Base
#cache_hit, #data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #latitude, #longitude, #province_code
Class Method Details
.response_attributes ⇒ Object
Get address components of a given type. Valid types are defined in Baidu’s Geocoding API documentation and include (among others):
:business
:cityCode
77
78
79
|
# File 'lib/geocoder/results/amap.rb', line 77
def self.response_attributes
%w[roads pois roadinters]
end
|
Instance Method Details
#address ⇒ Object
12
13
14
|
# File 'lib/geocoder/results/amap.rb', line 12
def address
formatted_address
end
|
#address_components ⇒ Object
50
51
52
|
# File 'lib/geocoder/results/amap.rb', line 50
def address_components
@data['addressComponent'] || @data
end
|
#city ⇒ Object
24
25
26
|
# File 'lib/geocoder/results/amap.rb', line 24
def city
address_components['city'] == [] ? province : address_components["city"]
end
|
#coordinates ⇒ Object
6
7
8
9
10
|
# File 'lib/geocoder/results/amap.rb', line 6
def coordinates
location = @data['location'] || @data['roadinters'].try(:first).try(:[], 'location') \
|| address_components.try(:[], 'streetNumber').try(:[], 'location')
location.to_s.split(",").reverse.map(&:to_f)
end
|
#country ⇒ Object
62
63
64
|
# File 'lib/geocoder/results/amap.rb', line 62
def country
"China"
end
|
#country_code ⇒ Object
66
67
68
|
# File 'lib/geocoder/results/amap.rb', line 66
def country_code
"CN"
end
|
#district ⇒ Object
28
29
30
|
# File 'lib/geocoder/results/amap.rb', line 28
def district
address_components['district']
end
|
46
47
48
|
# File 'lib/geocoder/results/amap.rb', line 46
def formatted_address
@data['formatted_address']
end
|
#postal_code ⇒ Object
58
59
60
|
# File 'lib/geocoder/results/amap.rb', line 58
def postal_code
""
end
|
#province ⇒ Object
20
21
22
|
# File 'lib/geocoder/results/amap.rb', line 20
def province
address_components['province']
end
|
#state ⇒ Object
16
17
18
|
# File 'lib/geocoder/results/amap.rb', line 16
def state
province
end
|
#state_code ⇒ Object
54
55
56
|
# File 'lib/geocoder/results/amap.rb', line 54
def state_code
""
end
|
#street ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/geocoder/results/amap.rb', line 32
def street
if address_components["neighborhood"]["name"] != []
return address_components["neighborhood"]["name"]
elsif address_components['township'] != []
return address_components["township"]
else
return @data['street'] || address_components['streetNumber'].try(:[], 'street')
end
end
|
#street_number ⇒ Object
42
43
44
|
# File 'lib/geocoder/results/amap.rb', line 42
def street_number
@data['number'] || address_components['streetNumber'].try(:[], 'number')
end
|