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


75
76
77
# File 'lib/geocoder/results/amap.rb', line 75

def self.response_attributes
  %w[roads pois roadinters]
end

Instance Method Details

#addressObject



10
11
12
# File 'lib/geocoder/results/amap.rb', line 10

def address
  @data['formatted_address']
end

#address_componentsObject



48
49
50
# File 'lib/geocoder/results/amap.rb', line 48

def address_components
  @data['addressComponent']
end

#cityObject



22
23
24
# File 'lib/geocoder/results/amap.rb', line 22

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

#coordinatesObject



6
7
8
# File 'lib/geocoder/results/amap.rb', line 6

def coordinates
  @data["roadinters"]['location'].split(",")
end

#countryObject



60
61
62
# File 'lib/geocoder/results/amap.rb', line 60

def country
  "China"
end

#country_codeObject



64
65
66
# File 'lib/geocoder/results/amap.rb', line 64

def country_code
  "CN"
end

#districtObject



26
27
28
# File 'lib/geocoder/results/amap.rb', line 26

def district
  address_components['district']
end

#formatted_addressObject



44
45
46
# File 'lib/geocoder/results/amap.rb', line 44

def formatted_address
  @data['formatted_address']
end

#postal_codeObject



56
57
58
# File 'lib/geocoder/results/amap.rb', line 56

def postal_code
  ""
end

#provinceObject



18
19
20
# File 'lib/geocoder/results/amap.rb', line 18

def province
  address_components['province']
end

#stateObject



14
15
16
# File 'lib/geocoder/results/amap.rb', line 14

def state
  province
end

#state_codeObject



52
53
54
# File 'lib/geocoder/results/amap.rb', line 52

def state_code
  ""
end

#streetObject



30
31
32
33
34
35
36
37
38
# File 'lib/geocoder/results/amap.rb', line 30

def street
  if address_components["neighborhood"]["name"] != []
    return address_components["neighborhood"]["name"]
  elsif address_components["streetNumber"]["street"] != []
    return address_components["streetNumber"]["street"]
  else
    return address_components["township"]
  end
end

#street_numberObject



40
41
42
# File 'lib/geocoder/results/amap.rb', line 40

def street_number
  address_components['streetNumber']["number"]
end