ultra-fast-mod 0.0.1
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 +7 -0
- data/geocoder-1.8.6/CHANGELOG.md +669 -0
- data/geocoder-1.8.6/LICENSE +20 -0
- data/geocoder-1.8.6/README.md +827 -0
- data/geocoder-1.8.6/bin/console +13 -0
- data/geocoder-1.8.6/bin/geocode +5 -0
- data/geocoder-1.8.6/examples/app_defined_lookup_services.rb +22 -0
- data/geocoder-1.8.6/examples/cache_bypass.rb +48 -0
- data/geocoder-1.8.6/examples/reverse_geocode_job.rb +40 -0
- data/geocoder-1.8.6/lib/easting_northing.rb +171 -0
- data/geocoder-1.8.6/lib/generators/geocoder/config/config_generator.rb +14 -0
- data/geocoder-1.8.6/lib/generators/geocoder/config/templates/initializer.rb +27 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/geolite_city_generator.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/geolite_country_generator.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/geocoder-1.8.6/lib/generators/geocoder/migration_version.rb +15 -0
- data/geocoder-1.8.6/lib/geocoder/cache.rb +77 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/base.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/generic.rb +35 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/redis.rb +34 -0
- data/geocoder-1.8.6/lib/geocoder/calculations.rb +420 -0
- data/geocoder-1.8.6/lib/geocoder/cli.rb +121 -0
- data/geocoder-1.8.6/lib/geocoder/configuration.rb +151 -0
- data/geocoder-1.8.6/lib/geocoder/configuration_hash.rb +11 -0
- data/geocoder-1.8.6/lib/geocoder/esri_token.rb +38 -0
- data/geocoder-1.8.6/lib/geocoder/exceptions.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/ip_address.rb +36 -0
- data/geocoder-1.8.6/lib/geocoder/kernel_logger.rb +25 -0
- data/geocoder-1.8.6/lib/geocoder/logger.rb +47 -0
- data/geocoder-1.8.6/lib/geocoder/lookup.rb +155 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/amap.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/amazon_location_service.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/azure.rb +56 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/baidu.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/baidu_ip.rb +30 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/base.rb +351 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/bing.rb +82 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/esri.rb +114 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/freegeoip.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoapify.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geocoder_ca.rb +53 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geocodio.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoip2.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google.rb +100 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_places_details.rb +64 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_places_search.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_premier.rb +61 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/here.rb +73 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location_io.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location_lite.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipbase.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipinfo_io_lite.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipstack.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/latlon.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/location_iq.rb +54 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/mapbox.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/mapquest.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind.rb +90 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind_local.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/nominatim.rb +64 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/opencagedata.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/osmnames.rb +57 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pc_miler.rb +87 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pdok_nl.rb +43 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pelias.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/photon.rb +89 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pointpin.rb +69 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/postcode_anywhere_uk.rb +50 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/smarty_streets.rb +68 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/telize.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/tencent.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/test.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/twogis.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/yandex.rb +61 -0
- data/geocoder-1.8.6/lib/geocoder/models/active_record.rb +51 -0
- data/geocoder-1.8.6/lib/geocoder/models/base.rb +39 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongo_base.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongo_mapper.rb +26 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongoid.rb +32 -0
- data/geocoder-1.8.6/lib/geocoder/query.rb +125 -0
- data/geocoder-1.8.6/lib/geocoder/railtie.rb +26 -0
- data/geocoder-1.8.6/lib/geocoder/request.rb +114 -0
- data/geocoder-1.8.6/lib/geocoder/results/abstract_api.rb +146 -0
- data/geocoder-1.8.6/lib/geocoder/results/amap.rb +87 -0
- data/geocoder-1.8.6/lib/geocoder/results/amazon_location_service.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/azure.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/results/baidu.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/results/baidu_ip.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/ban_data_gouv_fr.rb +282 -0
- data/geocoder-1.8.6/lib/geocoder/results/base.rb +79 -0
- data/geocoder-1.8.6/lib/geocoder/results/bing.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/results/db_ip_com.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/results/esri.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/results/freegeoip.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoapify.rb +179 -0
- data/geocoder-1.8.6/lib/geocoder/results/geocoder_ca.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/results/geocodio.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoip2.rb +76 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/results/google.rb +150 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_places_details.rb +39 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_places_search.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_premier.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/here.rb +77 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location.rb +22 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location_io.rb +21 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location_lite.rb +47 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipapi_com.rb +45 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipbase.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipdata_co.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipinfo_io_lite.rb +16 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipregistry.rb +304 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipstack.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/results/latlon.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/results/location_iq.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/mapbox.rb +80 -0
- data/geocoder-1.8.6/lib/geocoder/results/mapquest.rb +48 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind.rb +130 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind_local.rb +44 -0
- data/geocoder-1.8.6/lib/geocoder/results/melissa_street.rb +46 -0
- data/geocoder-1.8.6/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/nominatim.rb +121 -0
- data/geocoder-1.8.6/lib/geocoder/results/opencagedata.rb +100 -0
- data/geocoder-1.8.6/lib/geocoder/results/osmnames.rb +56 -0
- data/geocoder-1.8.6/lib/geocoder/results/pc_miler.rb +98 -0
- data/geocoder-1.8.6/lib/geocoder/results/pdok_nl.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/pelias.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/results/photon.rb +119 -0
- data/geocoder-1.8.6/lib/geocoder/results/pickpoint.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/pointpin.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/results/postcodes_io.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/smarty_streets.rb +142 -0
- data/geocoder-1.8.6/lib/geocoder/results/telize.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/tencent.rb +72 -0
- data/geocoder-1.8.6/lib/geocoder/results/test.rb +33 -0
- data/geocoder-1.8.6/lib/geocoder/results/twogis.rb +76 -0
- data/geocoder-1.8.6/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/results/yandex.rb +292 -0
- data/geocoder-1.8.6/lib/geocoder/sql.rb +110 -0
- data/geocoder-1.8.6/lib/geocoder/stores/active_record.rb +329 -0
- data/geocoder-1.8.6/lib/geocoder/stores/base.rb +115 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongo_base.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongo_mapper.rb +13 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongoid.rb +13 -0
- data/geocoder-1.8.6/lib/geocoder/util.rb +29 -0
- data/geocoder-1.8.6/lib/geocoder/version.rb +3 -0
- data/geocoder-1.8.6/lib/geocoder.rb +48 -0
- data/geocoder-1.8.6/lib/maxmind_database.rb +109 -0
- data/geocoder-1.8.6/lib/tasks/geocoder.rake +54 -0
- data/geocoder-1.8.6/lib/tasks/maxmind.rake +73 -0
- data/ultra-fast-mod.gemspec +12 -0
- metadata +214 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'geocoder/results/base'
|
|
4
|
+
|
|
5
|
+
module Geocoder
|
|
6
|
+
module Result
|
|
7
|
+
# https://apidocs.geoapify.com/docs/geocoding/api
|
|
8
|
+
class Geoapify < Base
|
|
9
|
+
def address(_format = :full)
|
|
10
|
+
properties['formatted']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def address_line1
|
|
14
|
+
properties['address_line1']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def address_line2
|
|
18
|
+
properties['address_line2']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def house_number
|
|
22
|
+
properties['housenumber']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def street
|
|
26
|
+
properties['street']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def postal_code
|
|
30
|
+
properties['postcode']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def district
|
|
34
|
+
properties['district']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def suburb
|
|
38
|
+
properties['suburb']
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def city
|
|
42
|
+
properties['city']
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def county
|
|
46
|
+
properties['county']
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def state
|
|
50
|
+
properties['state']
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Not currently available in the API
|
|
54
|
+
def state_code
|
|
55
|
+
''
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def country
|
|
59
|
+
properties['country']
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def country_code
|
|
63
|
+
return unless properties['country_code']
|
|
64
|
+
|
|
65
|
+
properties['country_code'].upcase
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def coordinates
|
|
69
|
+
return unless properties['lat']
|
|
70
|
+
return unless properties['lon']
|
|
71
|
+
|
|
72
|
+
[properties['lat'], properties['lon']]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# See: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
76
|
+
#
|
|
77
|
+
# Each feature has a "Point" type in the Geoapify API.
|
|
78
|
+
def geometry
|
|
79
|
+
return unless data['geometry']
|
|
80
|
+
|
|
81
|
+
symbol_hash data['geometry']
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# See: https://tools.ietf.org/html/rfc7946#section-5
|
|
85
|
+
def bounds
|
|
86
|
+
data['bbox']
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Type of the result, one of:
|
|
90
|
+
#
|
|
91
|
+
# * :unknown
|
|
92
|
+
# * :amenity
|
|
93
|
+
# * :building
|
|
94
|
+
# * :street
|
|
95
|
+
# * :suburb
|
|
96
|
+
# * :district
|
|
97
|
+
# * :postcode
|
|
98
|
+
# * :city
|
|
99
|
+
# * :county
|
|
100
|
+
# * :state
|
|
101
|
+
# * :country
|
|
102
|
+
#
|
|
103
|
+
def type
|
|
104
|
+
return :unknown unless properties['result_type']
|
|
105
|
+
|
|
106
|
+
properties['result_type'].to_sym
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Distance in meters to given bias:proximity or to given coordinates for
|
|
110
|
+
# reverse geocoding
|
|
111
|
+
def distance
|
|
112
|
+
properties['distance']
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Calculated rank for the result, containing the following keys:
|
|
116
|
+
#
|
|
117
|
+
# * `popularity` - The popularity score of the result
|
|
118
|
+
# * `confidence` - The confidence value of the result (0-1)
|
|
119
|
+
# * `match_type` - The result's match type, one of following:
|
|
120
|
+
# * full_match
|
|
121
|
+
# * inner_part
|
|
122
|
+
# * match_by_building
|
|
123
|
+
# * match_by_street
|
|
124
|
+
# * match_by_postcode
|
|
125
|
+
# * match_by_city_or_disrict
|
|
126
|
+
# * match_by_country_or_state
|
|
127
|
+
#
|
|
128
|
+
# Example:
|
|
129
|
+
# {
|
|
130
|
+
# popularity: 8.615793062435909,
|
|
131
|
+
# confidence: 0.88,
|
|
132
|
+
# match_type: :full_match
|
|
133
|
+
# }
|
|
134
|
+
def rank
|
|
135
|
+
return unless properties['rank']
|
|
136
|
+
|
|
137
|
+
r = symbol_hash(properties['rank'])
|
|
138
|
+
r[:match_type] = r[:match_type].to_sym if r[:match_type]
|
|
139
|
+
r
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Examples:
|
|
143
|
+
#
|
|
144
|
+
# Open
|
|
145
|
+
# {
|
|
146
|
+
# sourcename: 'openstreetmap',
|
|
147
|
+
# wheelchair: 'limited',
|
|
148
|
+
# wikidata: 'Q186125',
|
|
149
|
+
# wikipedia: 'en:Madison Square Garden',
|
|
150
|
+
# website: 'http://www.thegarden.com/',
|
|
151
|
+
# phone: '12124656741',
|
|
152
|
+
# osm_type: 'W',
|
|
153
|
+
# osm_id: 138141251,
|
|
154
|
+
# continent: 'North America',
|
|
155
|
+
# }
|
|
156
|
+
def datasource
|
|
157
|
+
return unless properties['datasource']
|
|
158
|
+
|
|
159
|
+
symbol_hash properties['datasource']
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
def properties
|
|
165
|
+
@properties ||= data['properties'] || {}
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def symbol_hash(orig_hash)
|
|
169
|
+
{}.tap do |result|
|
|
170
|
+
orig_hash.each_key do |key|
|
|
171
|
+
next unless orig_hash[key]
|
|
172
|
+
|
|
173
|
+
result[key.to_sym] = orig_hash[key]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class GeocoderCa < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
[@data['latt'].to_f, @data['longt'].to_f]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def address(format = :full)
|
|
11
|
+
"#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def street_address
|
|
15
|
+
"#{@data['stnumber']} #{@data['staddress']}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def city
|
|
19
|
+
@data['city'] or (@data['standard'] and @data['standard']['city']) or ""
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def state
|
|
23
|
+
@data['prov'] or (@data['standard'] and @data['standard']['prov']) or ""
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
alias_method :state_code, :state
|
|
27
|
+
|
|
28
|
+
def postal_code
|
|
29
|
+
@data['postal'] or (@data['standard'] and @data['standard']['postal']) or ""
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def country
|
|
33
|
+
country_code == 'CA' ? 'Canada' : 'United States'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def country_code
|
|
37
|
+
return nil if state.nil? || state == ""
|
|
38
|
+
canadian_province_abbreviations.include?(state) ? "CA" : "US"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.response_attributes
|
|
42
|
+
%w[latt longt inlatt inlongt distance stnumber staddress prov
|
|
43
|
+
NearRoad NearRoadDistance betweenRoad1 betweenRoad2
|
|
44
|
+
intersection major_intersection]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
response_attributes.each do |a|
|
|
48
|
+
define_method a do
|
|
49
|
+
@data[a]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
private # ----------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
def canadian_province_abbreviations
|
|
57
|
+
%w[ON QC NS NB MB BC PE SK AB NL]
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Geocodio < Base
|
|
5
|
+
def number
|
|
6
|
+
address_components["number"]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def street
|
|
10
|
+
address_components["street"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def suffix
|
|
14
|
+
address_components["suffix"]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def street_address
|
|
18
|
+
[number, address_components["formatted_street"]].compact.join(' ')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def state
|
|
22
|
+
address_components["state"]
|
|
23
|
+
end
|
|
24
|
+
alias_method :state_code, :state
|
|
25
|
+
|
|
26
|
+
def zip
|
|
27
|
+
# Postal code is not returned for Canada geocode results
|
|
28
|
+
address_components["zip"] || ""
|
|
29
|
+
end
|
|
30
|
+
alias_method :postal_code, :zip
|
|
31
|
+
|
|
32
|
+
def country
|
|
33
|
+
# Geocodio supports US and Canada, however they don't return the full
|
|
34
|
+
# country name.
|
|
35
|
+
|
|
36
|
+
if country_code == "CA"
|
|
37
|
+
"Canada"
|
|
38
|
+
else
|
|
39
|
+
"United States"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def country_code
|
|
44
|
+
address_components['country']
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def city
|
|
48
|
+
address_components["city"]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def postdirectional
|
|
52
|
+
address_components["postdirectional"]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def location
|
|
56
|
+
@data['location']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def coordinates
|
|
60
|
+
['lat', 'lng'].map{ |i| location[i].to_f } if location
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def accuracy
|
|
64
|
+
@data['accuracy'].to_f if @data.key?('accuracy')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def formatted_address(format = :full)
|
|
68
|
+
@data['formatted_address']
|
|
69
|
+
end
|
|
70
|
+
alias_method :address, :formatted_address
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def address_components
|
|
75
|
+
@data['address_components'] || {}
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder
|
|
4
|
+
module Result
|
|
5
|
+
class Geoip2 < Base
|
|
6
|
+
|
|
7
|
+
def coordinates
|
|
8
|
+
%w[latitude longitude].map do |l|
|
|
9
|
+
data.fetch('location', {}).fetch(l, 0.0)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def city
|
|
14
|
+
fetch_name(
|
|
15
|
+
data.fetch('city', {}).fetch('names', {})
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def state
|
|
20
|
+
fetch_name(
|
|
21
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {})
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def state_code
|
|
26
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def country
|
|
30
|
+
fetch_name(
|
|
31
|
+
data.fetch('country', {}).fetch('names', {})
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def country_code
|
|
36
|
+
data.fetch('country', {}).fetch('iso_code', '')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def postal_code
|
|
40
|
+
data.fetch('postal', {}).fetch('code', '')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.response_attributes
|
|
44
|
+
%w[ip]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
response_attributes.each do |a|
|
|
48
|
+
define_method a do
|
|
49
|
+
@data[a]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def language=(l)
|
|
54
|
+
@language = l.to_s
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def language
|
|
58
|
+
@language ||= default_language
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def data
|
|
62
|
+
@data.to_hash
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def default_language
|
|
68
|
+
@default_language = Geocoder.config[:language].to_s
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def fetch_name(names)
|
|
72
|
+
names[language] || names[default_language] || ''
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class GeoportailLu < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
geomlonlat['coordinates'].reverse if geolocalized?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def address
|
|
11
|
+
full_address
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def city
|
|
15
|
+
try_to_extract 'locality', detailled_address
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def state
|
|
19
|
+
'Luxembourg'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def state_code
|
|
23
|
+
'LU'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def postal_code
|
|
27
|
+
try_to_extract 'zip', detailled_address
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def street_address
|
|
31
|
+
[street_number, street].compact.join(' ')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def street_number
|
|
35
|
+
try_to_extract 'postnumber', detailled_address
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def street
|
|
39
|
+
try_to_extract 'street', detailled_address
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def full_address
|
|
43
|
+
data['address']
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def geomlonlat
|
|
47
|
+
data['geomlonlat']
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def detailled_address
|
|
51
|
+
data['AddressDetails']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
alias_method :country, :state
|
|
55
|
+
alias_method :province, :state
|
|
56
|
+
alias_method :country_code, :state_code
|
|
57
|
+
alias_method :province_code, :state_code
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def geolocalized?
|
|
62
|
+
!!try_to_extract('coordinates', geomlonlat)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def try_to_extract(key, hash)
|
|
66
|
+
if hash.is_a?(Hash) and hash.include?(key)
|
|
67
|
+
hash[key]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Google < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
['lat', 'lng'].map{ |i| geometry['location'][i] }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def address(format = :full)
|
|
11
|
+
formatted_address
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def neighborhood
|
|
15
|
+
if neighborhood = address_components_of_type(:neighborhood).first
|
|
16
|
+
neighborhood['long_name']
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def city
|
|
21
|
+
fields = [:locality, :sublocality,
|
|
22
|
+
:administrative_area_level_3,
|
|
23
|
+
:administrative_area_level_2]
|
|
24
|
+
fields.each do |f|
|
|
25
|
+
if entity = address_components_of_type(f).first
|
|
26
|
+
return entity['long_name']
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
return nil # no appropriate components found
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def state
|
|
33
|
+
if state = address_components_of_type(:administrative_area_level_1).first
|
|
34
|
+
state['long_name']
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def state_code
|
|
39
|
+
if state = address_components_of_type(:administrative_area_level_1).first
|
|
40
|
+
state['short_name']
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def sub_state
|
|
45
|
+
if state = address_components_of_type(:administrative_area_level_2).first
|
|
46
|
+
state['long_name']
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def sub_state_code
|
|
51
|
+
if state = address_components_of_type(:administrative_area_level_2).first
|
|
52
|
+
state['short_name']
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def country
|
|
57
|
+
if country = address_components_of_type(:country).first
|
|
58
|
+
country['long_name']
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def country_code
|
|
63
|
+
if country = address_components_of_type(:country).first
|
|
64
|
+
country['short_name']
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def postal_code
|
|
69
|
+
if postal = address_components_of_type(:postal_code).first
|
|
70
|
+
postal['long_name']
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def route
|
|
75
|
+
if route = address_components_of_type(:route).first
|
|
76
|
+
route['long_name']
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def street_number
|
|
81
|
+
if street_number = address_components_of_type(:street_number).first
|
|
82
|
+
street_number['long_name']
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def street_address
|
|
87
|
+
[street_number, route].compact.join(' ')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def types
|
|
91
|
+
@data['types']
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def formatted_address
|
|
95
|
+
@data['formatted_address']
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def address_components
|
|
99
|
+
@data['address_components']
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
##
|
|
103
|
+
# Get address components of a given type. Valid types are defined in
|
|
104
|
+
# Google's Geocoding API documentation and include (among others):
|
|
105
|
+
#
|
|
106
|
+
# :street_number
|
|
107
|
+
# :locality
|
|
108
|
+
# :neighborhood
|
|
109
|
+
# :route
|
|
110
|
+
# :postal_code
|
|
111
|
+
#
|
|
112
|
+
def address_components_of_type(type)
|
|
113
|
+
address_components.select{ |c| c['types'].include?(type.to_s) }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def geometry
|
|
117
|
+
@data['geometry']
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def precision
|
|
121
|
+
geometry['location_type'] if geometry
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def partial_match
|
|
125
|
+
@data['partial_match']
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def place_id
|
|
129
|
+
@data['place_id']
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def viewport
|
|
133
|
+
viewport = geometry['viewport'] || fail
|
|
134
|
+
bounding_box_from viewport
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def bounds
|
|
138
|
+
bounding_box_from geometry['bounds']
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
private
|
|
142
|
+
|
|
143
|
+
def bounding_box_from(box)
|
|
144
|
+
return nil unless box
|
|
145
|
+
south, west = %w(lat lng).map { |c| box['southwest'][c] }
|
|
146
|
+
north, east = %w(lat lng).map { |c| box['northeast'][c] }
|
|
147
|
+
[south, west, north, east]
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "geocoder/results/google"
|
|
2
|
+
|
|
3
|
+
module Geocoder
|
|
4
|
+
module Result
|
|
5
|
+
class GooglePlacesDetails < Google
|
|
6
|
+
def place_id
|
|
7
|
+
@data["place_id"]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def types
|
|
11
|
+
@data["types"] || []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def reviews
|
|
15
|
+
@data["reviews"] || []
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def rating
|
|
19
|
+
@data["rating"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def rating_count
|
|
23
|
+
@data["user_ratings_total"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def phone_number
|
|
27
|
+
@data["international_phone_number"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def website
|
|
31
|
+
@data["website"]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def photos
|
|
35
|
+
@data["photos"]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require "geocoder/results/google"
|
|
2
|
+
|
|
3
|
+
module Geocoder
|
|
4
|
+
module Result
|
|
5
|
+
class GooglePlacesSearch < Google
|
|
6
|
+
|
|
7
|
+
def types
|
|
8
|
+
@data["types"] || []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def rating
|
|
12
|
+
@data["rating"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def photos
|
|
16
|
+
@data["photos"]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def city
|
|
20
|
+
""
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def state
|
|
24
|
+
""
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def state_code
|
|
28
|
+
""
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def province
|
|
32
|
+
""
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def province_code
|
|
36
|
+
""
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def postal_code
|
|
40
|
+
""
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def country
|
|
44
|
+
""
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def country_code
|
|
48
|
+
""
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|