Class: Geocoder::Result::Amap

Inherits:
Base
  • Object
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

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Class Method Details

.response_attributesObject

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

#addressObject



12
13
14
# File 'lib/geocoder/results/amap.rb', line 12

def address
  formatted_address
end

#address_componentsObject



50
51
52
# File 'lib/geocoder/results/amap.rb', line 50

def address_components
  @data['addressComponent'] || @data
end

#cityObject



24
25
26
# File 'lib/geocoder/results/amap.rb', line 24

def city
  address_components['city'] == [] ? province : address_components["city"]
end

#coordinatesObject



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

#countryObject



62
63
64
# File 'lib/geocoder/results/amap.rb', line 62

def country
  "China"
end

#country_codeObject



66
67
68
# File 'lib/geocoder/results/amap.rb', line 66

def country_code
  "CN"
end

#districtObject



28
29
30
# File 'lib/geocoder/results/amap.rb', line 28

def district
  address_components['district']
end

#formatted_addressObject



46
47
48
# File 'lib/geocoder/results/amap.rb', line 46

def formatted_address
  @data['formatted_address']
end

#postal_codeObject



58
59
60
# File 'lib/geocoder/results/amap.rb', line 58

def postal_code
  ""
end

#provinceObject



20
21
22
# File 'lib/geocoder/results/amap.rb', line 20

def province
  address_components['province']
end

#stateObject



16
17
18
# File 'lib/geocoder/results/amap.rb', line 16

def state
  province
end

#state_codeObject



54
55
56
# File 'lib/geocoder/results/amap.rb', line 54

def state_code
  ""
end

#streetObject



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_numberObject



42
43
44
# File 'lib/geocoder/results/amap.rb', line 42

def street_number
  @data['number'] || address_components['streetNumber'].try(:[], 'number')
end