geocoder 1.5.1 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +107 -0
- data/LICENSE +1 -1
- data/README.md +364 -243
- data/bin/console +13 -0
- data/examples/app_defined_lookup_services.rb +22 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +6 -1
- data/lib/geocoder/cache.rb +16 -33
- data/lib/geocoder/cache_stores/base.rb +40 -0
- data/lib/geocoder/cache_stores/generic.rb +35 -0
- data/lib/geocoder/cache_stores/redis.rb +34 -0
- data/lib/geocoder/configuration.rb +19 -5
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +11 -1
- data/lib/geocoder/lookup.rb +42 -6
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +2 -2
- data/lib/geocoder/lookups/amazon_location_service.rb +58 -0
- data/lib/geocoder/lookups/azure.rb +56 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +15 -2
- data/lib/geocoder/lookups/base.rb +4 -1
- data/lib/geocoder/lookups/bing.rb +2 -2
- data/lib/geocoder/lookups/esri.rb +24 -5
- data/lib/geocoder/lookups/freegeoip.rb +12 -10
- data/lib/geocoder/lookups/geoapify.rb +78 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/geoip2.rb +4 -0
- data/lib/geocoder/lookups/geoportail_lu.rb +1 -1
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +26 -12
- data/lib/geocoder/lookups/google_places_search.rb +44 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/here.rb +27 -31
- data/lib/geocoder/lookups/ip2location.rb +10 -14
- data/lib/geocoder/lookups/ip2location_io.rb +62 -0
- data/lib/geocoder/lookups/ip2location_lite.rb +40 -0
- data/lib/geocoder/lookups/ipbase.rb +49 -0
- data/lib/geocoder/lookups/ipdata_co.rb +1 -1
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/latlon.rb +1 -2
- data/lib/geocoder/lookups/location_iq.rb +5 -1
- data/lib/geocoder/lookups/mapbox.rb +3 -3
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pc_miler.rb +85 -0
- data/lib/geocoder/lookups/pdok_nl.rb +43 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/lookups/pickpoint.rb +1 -1
- data/lib/geocoder/lookups/smarty_streets.rb +6 -1
- data/lib/geocoder/lookups/telize.rb +1 -1
- data/lib/geocoder/lookups/tencent.rb +9 -9
- data/lib/geocoder/lookups/test.rb +5 -0
- data/lib/geocoder/lookups/twogis.rb +58 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +6 -7
- data/lib/geocoder/query.rb +1 -1
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/amazon_location_service.rb +62 -0
- data/lib/geocoder/results/azure.rb +65 -0
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +28 -3
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/esri.rb +5 -2
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/here.rb +20 -22
- data/lib/geocoder/results/ip2location_io.rb +21 -0
- data/lib/geocoder/results/ip2location_lite.rb +47 -0
- data/lib/geocoder/results/ipbase.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/mapbox.rb +34 -10
- data/lib/geocoder/results/melissa_street.rb +46 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +27 -15
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pc_miler.rb +98 -0
- data/lib/geocoder/results/pdok_nl.rb +62 -0
- data/lib/geocoder/results/photon.rb +119 -0
- data/lib/geocoder/results/twogis.rb +76 -0
- data/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/results/yandex.rb +217 -59
- data/lib/geocoder/sql.rb +4 -4
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +12 -12
- data/lib/tasks/maxmind.rake +1 -1
- metadata +81 -23
- data/examples/autoexpire_cache_dalli.rb +0 -62
- data/examples/autoexpire_cache_redis.rb +0 -28
- data/lib/geocoder/lookups/dstk.rb +0 -22
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/results/dstk.rb +0 -6
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/hash_recursive_merge.rb +0 -74
@@ -0,0 +1,304 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Ipregistry < Base
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
super
|
8
|
+
|
9
|
+
@data = flatten_hash(data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def coordinates
|
13
|
+
[@data['location_latitude'], @data['location_longitude']]
|
14
|
+
end
|
15
|
+
|
16
|
+
def flatten_hash(hash)
|
17
|
+
hash.each_with_object({}) do |(k, v), h|
|
18
|
+
if v.is_a? Hash
|
19
|
+
flatten_hash(v).map do |h_k, h_v|
|
20
|
+
h["#{k}_#{h_k}".to_s] = h_v
|
21
|
+
end
|
22
|
+
else
|
23
|
+
h[k] = v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private :flatten_hash
|
29
|
+
|
30
|
+
def city
|
31
|
+
@data['location_city']
|
32
|
+
end
|
33
|
+
|
34
|
+
def country
|
35
|
+
@data['location_country_name']
|
36
|
+
end
|
37
|
+
|
38
|
+
def country_code
|
39
|
+
@data['location_country_code']
|
40
|
+
end
|
41
|
+
|
42
|
+
def postal_code
|
43
|
+
@data['location_postal']
|
44
|
+
end
|
45
|
+
|
46
|
+
def state
|
47
|
+
@data['location_region_name']
|
48
|
+
end
|
49
|
+
|
50
|
+
def state_code
|
51
|
+
@data['location_region_code']
|
52
|
+
end
|
53
|
+
|
54
|
+
# methods for fields specific to Ipregistry
|
55
|
+
|
56
|
+
def ip
|
57
|
+
@data["ip"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def type
|
61
|
+
@data["type"]
|
62
|
+
end
|
63
|
+
|
64
|
+
def hostname
|
65
|
+
@data["hostname"]
|
66
|
+
end
|
67
|
+
|
68
|
+
def carrier_name
|
69
|
+
@data["carrier_name"]
|
70
|
+
end
|
71
|
+
|
72
|
+
def carrier_mcc
|
73
|
+
@data["carrier_mcc"]
|
74
|
+
end
|
75
|
+
|
76
|
+
def carrier_mnc
|
77
|
+
@data["carrier_mnc"]
|
78
|
+
end
|
79
|
+
|
80
|
+
def connection_asn
|
81
|
+
@data["connection_asn"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def connection_domain
|
85
|
+
@data["connection_domain"]
|
86
|
+
end
|
87
|
+
|
88
|
+
def connection_organization
|
89
|
+
@data["connection_organization"]
|
90
|
+
end
|
91
|
+
|
92
|
+
def connection_type
|
93
|
+
@data["connection_type"]
|
94
|
+
end
|
95
|
+
|
96
|
+
def currency_code
|
97
|
+
@data["currency_code"]
|
98
|
+
end
|
99
|
+
|
100
|
+
def currency_name
|
101
|
+
@data["currency_name"]
|
102
|
+
end
|
103
|
+
|
104
|
+
def currency_plural
|
105
|
+
@data["currency_plural"]
|
106
|
+
end
|
107
|
+
|
108
|
+
def currency_symbol
|
109
|
+
@data["currency_symbol"]
|
110
|
+
end
|
111
|
+
|
112
|
+
def currency_symbol_native
|
113
|
+
@data["currency_symbol_native"]
|
114
|
+
end
|
115
|
+
|
116
|
+
def currency_format_negative_prefix
|
117
|
+
@data["currency_format_negative_prefix"]
|
118
|
+
end
|
119
|
+
|
120
|
+
def currency_format_negative_suffix
|
121
|
+
@data["currency_format_negative_suffix"]
|
122
|
+
end
|
123
|
+
|
124
|
+
def currency_format_positive_prefix
|
125
|
+
@data["currency_format_positive_prefix"]
|
126
|
+
end
|
127
|
+
|
128
|
+
def currency_format_positive_suffix
|
129
|
+
@data["currency_format_positive_suffix"]
|
130
|
+
end
|
131
|
+
|
132
|
+
def location_continent_code
|
133
|
+
@data["location_continent_code"]
|
134
|
+
end
|
135
|
+
|
136
|
+
def location_continent_name
|
137
|
+
@data["location_continent_name"]
|
138
|
+
end
|
139
|
+
|
140
|
+
def location_country_area
|
141
|
+
@data["location_country_area"]
|
142
|
+
end
|
143
|
+
|
144
|
+
def location_country_borders
|
145
|
+
@data["location_country_borders"]
|
146
|
+
end
|
147
|
+
|
148
|
+
def location_country_calling_code
|
149
|
+
@data["location_country_calling_code"]
|
150
|
+
end
|
151
|
+
|
152
|
+
def location_country_capital
|
153
|
+
@data["location_country_capital"]
|
154
|
+
end
|
155
|
+
|
156
|
+
def location_country_code
|
157
|
+
@data["location_country_code"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def location_country_name
|
161
|
+
@data["location_country_name"]
|
162
|
+
end
|
163
|
+
|
164
|
+
def location_country_population
|
165
|
+
@data["location_country_population"]
|
166
|
+
end
|
167
|
+
|
168
|
+
def location_country_population_density
|
169
|
+
@data["location_country_population_density"]
|
170
|
+
end
|
171
|
+
|
172
|
+
def location_country_flag_emoji
|
173
|
+
@data["location_country_flag_emoji"]
|
174
|
+
end
|
175
|
+
|
176
|
+
def location_country_flag_emoji_unicode
|
177
|
+
@data["location_country_flag_emoji_unicode"]
|
178
|
+
end
|
179
|
+
|
180
|
+
def location_country_flag_emojitwo
|
181
|
+
@data["location_country_flag_emojitwo"]
|
182
|
+
end
|
183
|
+
|
184
|
+
def location_country_flag_noto
|
185
|
+
@data["location_country_flag_noto"]
|
186
|
+
end
|
187
|
+
|
188
|
+
def location_country_flag_twemoji
|
189
|
+
@data["location_country_flag_twemoji"]
|
190
|
+
end
|
191
|
+
|
192
|
+
def location_country_flag_wikimedia
|
193
|
+
@data["location_country_flag_wikimedia"]
|
194
|
+
end
|
195
|
+
|
196
|
+
def location_country_languages
|
197
|
+
@data["location_country_languages"]
|
198
|
+
end
|
199
|
+
|
200
|
+
def location_country_tld
|
201
|
+
@data["location_country_tld"]
|
202
|
+
end
|
203
|
+
|
204
|
+
def location_region_code
|
205
|
+
@data["location_region_code"]
|
206
|
+
end
|
207
|
+
|
208
|
+
def location_region_name
|
209
|
+
@data["location_region_name"]
|
210
|
+
end
|
211
|
+
|
212
|
+
def location_city
|
213
|
+
@data["location_city"]
|
214
|
+
end
|
215
|
+
|
216
|
+
def location_postal
|
217
|
+
@data["location_postal"]
|
218
|
+
end
|
219
|
+
|
220
|
+
def location_latitude
|
221
|
+
@data["location_latitude"]
|
222
|
+
end
|
223
|
+
|
224
|
+
def location_longitude
|
225
|
+
@data["location_longitude"]
|
226
|
+
end
|
227
|
+
|
228
|
+
def location_language_code
|
229
|
+
@data["location_language_code"]
|
230
|
+
end
|
231
|
+
|
232
|
+
def location_language_name
|
233
|
+
@data["location_language_name"]
|
234
|
+
end
|
235
|
+
|
236
|
+
def location_language_native
|
237
|
+
@data["location_language_native"]
|
238
|
+
end
|
239
|
+
|
240
|
+
def location_in_eu
|
241
|
+
@data["location_in_eu"]
|
242
|
+
end
|
243
|
+
|
244
|
+
def security_is_bogon
|
245
|
+
@data["security_is_bogon"]
|
246
|
+
end
|
247
|
+
|
248
|
+
def security_is_cloud_provider
|
249
|
+
@data["security_is_cloud_provider"]
|
250
|
+
end
|
251
|
+
|
252
|
+
def security_is_tor
|
253
|
+
@data["security_is_tor"]
|
254
|
+
end
|
255
|
+
|
256
|
+
def security_is_tor_exit
|
257
|
+
@data["security_is_tor_exit"]
|
258
|
+
end
|
259
|
+
|
260
|
+
def security_is_proxy
|
261
|
+
@data["security_is_proxy"]
|
262
|
+
end
|
263
|
+
|
264
|
+
def security_is_anonymous
|
265
|
+
@data["security_is_anonymous"]
|
266
|
+
end
|
267
|
+
|
268
|
+
def security_is_abuser
|
269
|
+
@data["security_is_abuser"]
|
270
|
+
end
|
271
|
+
|
272
|
+
def security_is_attacker
|
273
|
+
@data["security_is_attacker"]
|
274
|
+
end
|
275
|
+
|
276
|
+
def security_is_threat
|
277
|
+
@data["security_is_threat"]
|
278
|
+
end
|
279
|
+
|
280
|
+
def time_zone_id
|
281
|
+
@data["time_zone_id"]
|
282
|
+
end
|
283
|
+
|
284
|
+
def time_zone_abbreviation
|
285
|
+
@data["time_zone_abbreviation"]
|
286
|
+
end
|
287
|
+
|
288
|
+
def time_zone_current_time
|
289
|
+
@data["time_zone_current_time"]
|
290
|
+
end
|
291
|
+
|
292
|
+
def time_zone_name
|
293
|
+
@data["time_zone_name"]
|
294
|
+
end
|
295
|
+
|
296
|
+
def time_zone_offset
|
297
|
+
@data["time_zone_offset"]
|
298
|
+
end
|
299
|
+
|
300
|
+
def time_zone_in_daylight_saving
|
301
|
+
@data["time_zone_in_daylight_saving"]
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
@@ -16,37 +16,61 @@ module Geocoder::Result
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def city
|
19
|
-
context_part('place')
|
19
|
+
data_part('place') || context_part('place')
|
20
20
|
end
|
21
21
|
|
22
22
|
def state
|
23
|
-
context_part('region')
|
23
|
+
data_part('region') || context_part('region')
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
def state_code
|
27
|
+
if id_matches_name?(data['id'], 'region')
|
28
|
+
value = data['properties']['short_code']
|
29
|
+
else
|
30
|
+
value = context_part('region', 'short_code')
|
31
|
+
end
|
32
|
+
|
33
|
+
value.split('-').last unless value.nil?
|
34
|
+
end
|
27
35
|
|
28
36
|
def postal_code
|
29
|
-
context_part('postcode')
|
37
|
+
data_part('postcode') || context_part('postcode')
|
30
38
|
end
|
31
39
|
|
32
40
|
def country
|
33
|
-
context_part('country')
|
41
|
+
data_part('country') || context_part('country')
|
34
42
|
end
|
35
43
|
|
36
|
-
|
44
|
+
def country_code
|
45
|
+
if id_matches_name?(data['id'], 'country')
|
46
|
+
value = data['properties']['short_code']
|
47
|
+
else
|
48
|
+
value = context_part('country', 'short_code')
|
49
|
+
end
|
50
|
+
|
51
|
+
value.upcase unless value.nil?
|
52
|
+
end
|
37
53
|
|
38
54
|
def neighborhood
|
39
|
-
context_part('neighborhood')
|
55
|
+
data_part('neighborhood') || context_part('neighborhood')
|
40
56
|
end
|
41
57
|
|
42
58
|
def address
|
43
|
-
[place_name
|
59
|
+
data['place_name']
|
44
60
|
end
|
45
61
|
|
46
62
|
private
|
47
63
|
|
48
|
-
def
|
49
|
-
|
64
|
+
def id_matches_name?(id, name)
|
65
|
+
id =~ Regexp.new(name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def data_part(name)
|
69
|
+
data['text'] if id_matches_name?(data['id'], name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def context_part(name, key = 'text')
|
73
|
+
(context.detect { |c| id_matches_name?(c['id'], name) } || {})[key]
|
50
74
|
end
|
51
75
|
|
52
76
|
def context
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class MelissaStreet < Base
|
5
|
+
def address(format = :full)
|
6
|
+
@data['FormattedAddress']
|
7
|
+
end
|
8
|
+
|
9
|
+
def street_address
|
10
|
+
@data['AddressLine1']
|
11
|
+
end
|
12
|
+
|
13
|
+
def suffix
|
14
|
+
@data['ThoroughfareTrailingType']
|
15
|
+
end
|
16
|
+
|
17
|
+
def number
|
18
|
+
@data['PremisesNumber']
|
19
|
+
end
|
20
|
+
|
21
|
+
def city
|
22
|
+
@data['Locality']
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_code
|
26
|
+
@data['AdministrativeArea']
|
27
|
+
end
|
28
|
+
alias_method :state, :state_code
|
29
|
+
|
30
|
+
def country
|
31
|
+
@data['CountryName']
|
32
|
+
end
|
33
|
+
|
34
|
+
def country_code
|
35
|
+
@data['CountryISO3166_1_Alpha2']
|
36
|
+
end
|
37
|
+
|
38
|
+
def postal_code
|
39
|
+
@data['PostalCode']
|
40
|
+
end
|
41
|
+
|
42
|
+
def coordinates
|
43
|
+
[@data['Latitude'].to_f, @data['Longitude'].to_f]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class NationaalGeoregisterNl < Base
|
5
|
+
|
6
|
+
def response_attributes
|
7
|
+
@data
|
8
|
+
end
|
9
|
+
|
10
|
+
def coordinates
|
11
|
+
@data['centroide_ll'][6..-2].split(' ').map(&:to_f).reverse
|
12
|
+
end
|
13
|
+
|
14
|
+
def formatted_address
|
15
|
+
@data['weergavenaam']
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :address, :formatted_address
|
19
|
+
|
20
|
+
def province
|
21
|
+
@data['provincienaam']
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :state, :province
|
25
|
+
|
26
|
+
def city
|
27
|
+
@data['woonplaatsnaam']
|
28
|
+
end
|
29
|
+
|
30
|
+
def district
|
31
|
+
@data['gemeentenaam']
|
32
|
+
end
|
33
|
+
|
34
|
+
def street
|
35
|
+
@data['straatnaam']
|
36
|
+
end
|
37
|
+
|
38
|
+
def street_number
|
39
|
+
@data['huis_nlt']
|
40
|
+
end
|
41
|
+
|
42
|
+
def address_components
|
43
|
+
@data
|
44
|
+
end
|
45
|
+
|
46
|
+
def state_code
|
47
|
+
@data['provinciecode']
|
48
|
+
end
|
49
|
+
|
50
|
+
def postal_code
|
51
|
+
@data['postcode']
|
52
|
+
end
|
53
|
+
|
54
|
+
def country
|
55
|
+
"Netherlands"
|
56
|
+
end
|
57
|
+
|
58
|
+
def country_code
|
59
|
+
"NL"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -4,12 +4,12 @@ module Geocoder::Result
|
|
4
4
|
class Nominatim < Base
|
5
5
|
|
6
6
|
def poi
|
7
|
-
return
|
7
|
+
return address_data[place_type] if address_data.key?(place_type)
|
8
8
|
return nil
|
9
9
|
end
|
10
10
|
|
11
11
|
def house_number
|
12
|
-
|
12
|
+
address_data['house_number']
|
13
13
|
end
|
14
14
|
|
15
15
|
def address
|
@@ -18,65 +18,71 @@ module Geocoder::Result
|
|
18
18
|
|
19
19
|
def street
|
20
20
|
%w[road pedestrian highway].each do |key|
|
21
|
-
return
|
21
|
+
return address_data[key] if address_data.key?(key)
|
22
22
|
end
|
23
23
|
return nil
|
24
24
|
end
|
25
25
|
|
26
26
|
def city
|
27
27
|
%w[city town village hamlet].each do |key|
|
28
|
-
return
|
28
|
+
return address_data[key] if address_data.key?(key)
|
29
29
|
end
|
30
30
|
return nil
|
31
31
|
end
|
32
32
|
|
33
33
|
def village
|
34
|
-
|
34
|
+
address_data['village']
|
35
35
|
end
|
36
36
|
|
37
37
|
def town
|
38
|
-
|
38
|
+
address_data['town']
|
39
39
|
end
|
40
40
|
|
41
41
|
def state
|
42
|
-
|
42
|
+
address_data['state']
|
43
43
|
end
|
44
44
|
|
45
45
|
alias_method :state_code, :state
|
46
46
|
|
47
47
|
def postal_code
|
48
|
-
|
48
|
+
address_data['postcode']
|
49
49
|
end
|
50
50
|
|
51
51
|
def county
|
52
|
-
|
52
|
+
address_data['county']
|
53
53
|
end
|
54
54
|
|
55
55
|
def country
|
56
|
-
|
56
|
+
address_data['country']
|
57
57
|
end
|
58
58
|
|
59
59
|
def country_code
|
60
|
-
|
60
|
+
address_data['country_code']
|
61
61
|
end
|
62
62
|
|
63
63
|
def suburb
|
64
|
-
|
64
|
+
address_data['suburb']
|
65
65
|
end
|
66
66
|
|
67
67
|
def city_district
|
68
|
-
|
68
|
+
address_data['city_district']
|
69
69
|
end
|
70
70
|
|
71
71
|
def state_district
|
72
|
-
|
72
|
+
address_data['state_district']
|
73
73
|
end
|
74
74
|
|
75
75
|
def neighbourhood
|
76
|
-
|
76
|
+
address_data['neighbourhood']
|
77
|
+
end
|
78
|
+
|
79
|
+
def municipality
|
80
|
+
address_data['municipality']
|
77
81
|
end
|
78
82
|
|
79
83
|
def coordinates
|
84
|
+
return [] unless @data['lat'] && @data['lon']
|
85
|
+
|
80
86
|
[@data['lat'].to_f, @data['lon'].to_f]
|
81
87
|
end
|
82
88
|
|
@@ -105,5 +111,11 @@ module Geocoder::Result
|
|
105
111
|
end
|
106
112
|
end
|
107
113
|
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def address_data
|
118
|
+
@data['address'] || {}
|
119
|
+
end
|
108
120
|
end
|
109
121
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class Osmnames < Base
|
5
|
+
def address
|
6
|
+
@data['display_name']
|
7
|
+
end
|
8
|
+
|
9
|
+
def coordinates
|
10
|
+
[@data['lat'].to_f, @data['lon'].to_f]
|
11
|
+
end
|
12
|
+
|
13
|
+
def viewport
|
14
|
+
west, south, east, north = @data['boundingbox'].map(&:to_f)
|
15
|
+
[south, west, north, east]
|
16
|
+
end
|
17
|
+
|
18
|
+
def state
|
19
|
+
@data['state']
|
20
|
+
end
|
21
|
+
alias_method :state_code, :state
|
22
|
+
|
23
|
+
def place_class
|
24
|
+
@data['class']
|
25
|
+
end
|
26
|
+
|
27
|
+
def place_type
|
28
|
+
@data['type']
|
29
|
+
end
|
30
|
+
|
31
|
+
def postal_code
|
32
|
+
''
|
33
|
+
end
|
34
|
+
|
35
|
+
def country_code
|
36
|
+
@data['country_code']
|
37
|
+
end
|
38
|
+
|
39
|
+
def country
|
40
|
+
@data['country']
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.response_attributes
|
44
|
+
%w[house_number street city name osm_id osm_type boundingbox place_rank
|
45
|
+
importance county rank name_suffix]
|
46
|
+
end
|
47
|
+
|
48
|
+
response_attributes.each do |a|
|
49
|
+
unless method_defined?(a)
|
50
|
+
define_method a do
|
51
|
+
@data[a]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|