geocoder 1.4.9 → 1.6.7
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 +60 -0
- data/LICENSE +1 -1
- data/README.md +350 -979
- data/bin/console +13 -0
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +1 -1
- data/lib/geocoder/cache.rb +4 -0
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +3 -2
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/exceptions.rb +1 -1
- data/lib/geocoder/ip_address.rb +16 -2
- data/lib/geocoder/lookup.rb +9 -5
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +7 -3
- data/lib/geocoder/lookups/baidu.rb +14 -10
- data/lib/geocoder/lookups/baidu_ip.rb +7 -36
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +18 -5
- data/lib/geocoder/lookups/base.rb +27 -4
- data/lib/geocoder/lookups/bing.rb +10 -13
- data/lib/geocoder/lookups/db_ip_com.rb +9 -6
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +44 -28
- data/lib/geocoder/lookups/freegeoip.rb +11 -7
- data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
- data/lib/geocoder/lookups/geocodio.rb +5 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
- data/lib/geocoder/lookups/google.rb +15 -10
- data/lib/geocoder/lookups/google_places_details.rb +11 -17
- data/lib/geocoder/lookups/google_places_search.rb +30 -4
- data/lib/geocoder/lookups/google_premier.rb +14 -0
- data/lib/geocoder/lookups/here.rb +29 -23
- data/lib/geocoder/lookups/ip2location.rb +67 -0
- data/lib/geocoder/lookups/ipapi_com.rb +9 -13
- data/lib/geocoder/lookups/ipdata_co.rb +9 -4
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +11 -29
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +11 -12
- data/lib/geocoder/lookups/latlon.rb +5 -6
- data/lib/geocoder/lookups/location_iq.rb +10 -4
- data/lib/geocoder/lookups/mapbox.rb +7 -6
- data/lib/geocoder/lookups/mapquest.rb +4 -5
- data/lib/geocoder/lookups/maxmind.rb +6 -6
- data/lib/geocoder/lookups/maxmind_geoip2.rb +8 -7
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/nominatim.rb +4 -4
- data/lib/geocoder/lookups/opencagedata.rb +6 -5
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +8 -9
- data/lib/geocoder/lookups/pickpoint.rb +9 -3
- data/lib/geocoder/lookups/pointpin.rb +10 -9
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +4 -5
- data/lib/geocoder/lookups/postcodes_io.rb +6 -3
- data/lib/geocoder/lookups/smarty_streets.rb +26 -11
- data/lib/geocoder/lookups/telize.rb +24 -4
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +7 -8
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +27 -2
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +1 -6
- data/lib/geocoder/results/freegeoip.rb +0 -5
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geoip2.rb +0 -4
- data/lib/geocoder/results/geoportail_lu.rb +5 -3
- data/lib/geocoder/results/here.rb +4 -1
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipdata_co.rb +0 -5
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +4 -0
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/smarty_streets.rb +48 -18
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +1 -1
- 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/stores/active_record.rb +1 -3
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +3 -3
- metadata +27 -23
- data/lib/geocoder/lookups/geocoder_us.rb +0 -43
- data/lib/geocoder/lookups/mapzen.rb +0 -15
- data/lib/geocoder/lookups/okf.rb +0 -44
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/mapzen.rb +0 -5
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -71
- data/lib/hash_recursive_merge.rb +0 -74
data/lib/geocoder/sql.rb
CHANGED
|
@@ -44,13 +44,13 @@ module Geocoder
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr)
|
|
47
|
-
spans = "#{lat_attr} BETWEEN #{sw_lat} AND #{ne_lat} AND "
|
|
47
|
+
spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND "
|
|
48
48
|
# handle box that spans 180 longitude
|
|
49
49
|
if sw_lng.to_f > ne_lng.to_f
|
|
50
|
-
spans + "(#{lon_attr} BETWEEN #{sw_lng} AND 180 OR " +
|
|
51
|
-
"#{lon_attr} BETWEEN -180 AND #{ne_lng})"
|
|
50
|
+
spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " +
|
|
51
|
+
"#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})"
|
|
52
52
|
else
|
|
53
|
-
spans + "#{lon_attr} BETWEEN #{sw_lng} AND #{ne_lng}"
|
|
53
|
+
spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}"
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -60,7 +60,7 @@ module Geocoder::Store
|
|
|
60
60
|
# corner followed by the northeast corner of the box
|
|
61
61
|
# (<tt>[[sw_lat, sw_lon], [ne_lat, ne_lon]]</tt>).
|
|
62
62
|
#
|
|
63
|
-
scope :within_bounding_box, lambda{
|
|
63
|
+
scope :within_bounding_box, lambda{ |*bounds|
|
|
64
64
|
sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds
|
|
65
65
|
if sw_lat && sw_lng && ne_lat && ne_lng
|
|
66
66
|
where(Geocoder::Sql.within_bounding_box(
|
|
@@ -166,8 +166,6 @@ module Geocoder::Store
|
|
|
166
166
|
}
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
private # ----------------------------------------------------------------
|
|
170
|
-
|
|
171
169
|
##
|
|
172
170
|
# SQL for calculating distance based on the current database's
|
|
173
171
|
# capabilities (trig functions?).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Geocoder
|
|
4
|
+
module Util
|
|
5
|
+
#
|
|
6
|
+
# Recursive version of Hash#merge!
|
|
7
|
+
#
|
|
8
|
+
# Adds the contents of +h2+ to +h1+,
|
|
9
|
+
# merging entries in +h1+ with duplicate keys with those from +h2+.
|
|
10
|
+
#
|
|
11
|
+
# Compared with Hash#merge!, this method supports nested hashes.
|
|
12
|
+
# When both +h1+ and +h2+ contains an entry with the same key,
|
|
13
|
+
# it merges and returns the values from both hashes.
|
|
14
|
+
#
|
|
15
|
+
# h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
|
16
|
+
# h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
|
|
17
|
+
# recursive_hash_merge(h1, h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
|
|
18
|
+
#
|
|
19
|
+
# Simply using Hash#merge! would return
|
|
20
|
+
#
|
|
21
|
+
# h1.merge!(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
|
22
|
+
#
|
|
23
|
+
def self.recursive_hash_merge(h1, h2)
|
|
24
|
+
h1.merge!(h2) do |_key, oldval, newval|
|
|
25
|
+
oldval.class == h1.class ? self.recursive_hash_merge(oldval, newval) : newval
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/geocoder/version.rb
CHANGED
data/lib/maxmind_database.rb
CHANGED
|
@@ -96,9 +96,9 @@ module Geocoder
|
|
|
96
96
|
|
|
97
97
|
def archive_url_path(package)
|
|
98
98
|
{
|
|
99
|
-
geolite_country_csv: "
|
|
100
|
-
geolite_city_csv: "
|
|
101
|
-
geolite_asn_csv: "
|
|
99
|
+
geolite_country_csv: "GeoLite2-Country-CSV.zip",
|
|
100
|
+
geolite_city_csv: "GeoLite2-City-CSV.zip",
|
|
101
|
+
geolite_asn_csv: "GeoLite2-ASN-CSV.zip"
|
|
102
102
|
}[package]
|
|
103
103
|
end
|
|
104
104
|
|
metadata
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: geocoder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Reisner
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
frameworks too.
|
|
13
|
+
description: Object geocoding (by street or IP address), reverse geocoding (coordinates
|
|
14
|
+
to street address), distance queries for ActiveRecord and Mongoid, result caching,
|
|
15
|
+
and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
|
|
17
16
|
email:
|
|
18
17
|
- alex@alexreisner.com
|
|
19
18
|
executables:
|
|
@@ -24,11 +23,13 @@ files:
|
|
|
24
23
|
- CHANGELOG.md
|
|
25
24
|
- LICENSE
|
|
26
25
|
- README.md
|
|
26
|
+
- bin/console
|
|
27
27
|
- bin/geocode
|
|
28
28
|
- examples/autoexpire_cache_dalli.rb
|
|
29
29
|
- examples/autoexpire_cache_redis.rb
|
|
30
30
|
- examples/cache_bypass.rb
|
|
31
31
|
- examples/reverse_geocode_job.rb
|
|
32
|
+
- lib/easting_northing.rb
|
|
32
33
|
- lib/generators/geocoder/config/config_generator.rb
|
|
33
34
|
- lib/generators/geocoder/config/templates/initializer.rb
|
|
34
35
|
- lib/generators/geocoder/maxmind/geolite_city_generator.rb
|
|
@@ -48,6 +49,7 @@ files:
|
|
|
48
49
|
- lib/geocoder/kernel_logger.rb
|
|
49
50
|
- lib/geocoder/logger.rb
|
|
50
51
|
- lib/geocoder/lookup.rb
|
|
52
|
+
- lib/geocoder/lookups/abstract_api.rb
|
|
51
53
|
- lib/geocoder/lookups/amap.rb
|
|
52
54
|
- lib/geocoder/lookups/baidu.rb
|
|
53
55
|
- lib/geocoder/lookups/baidu_ip.rb
|
|
@@ -59,7 +61,6 @@ files:
|
|
|
59
61
|
- lib/geocoder/lookups/esri.rb
|
|
60
62
|
- lib/geocoder/lookups/freegeoip.rb
|
|
61
63
|
- lib/geocoder/lookups/geocoder_ca.rb
|
|
62
|
-
- lib/geocoder/lookups/geocoder_us.rb
|
|
63
64
|
- lib/geocoder/lookups/geocodio.rb
|
|
64
65
|
- lib/geocoder/lookups/geoip2.rb
|
|
65
66
|
- lib/geocoder/lookups/geoportail_lu.rb
|
|
@@ -68,22 +69,24 @@ files:
|
|
|
68
69
|
- lib/geocoder/lookups/google_places_search.rb
|
|
69
70
|
- lib/geocoder/lookups/google_premier.rb
|
|
70
71
|
- lib/geocoder/lookups/here.rb
|
|
72
|
+
- lib/geocoder/lookups/ip2location.rb
|
|
71
73
|
- lib/geocoder/lookups/ipapi_com.rb
|
|
72
74
|
- lib/geocoder/lookups/ipdata_co.rb
|
|
75
|
+
- lib/geocoder/lookups/ipgeolocation.rb
|
|
73
76
|
- lib/geocoder/lookups/ipinfo_io.rb
|
|
77
|
+
- lib/geocoder/lookups/ipregistry.rb
|
|
74
78
|
- lib/geocoder/lookups/ipstack.rb
|
|
75
79
|
- lib/geocoder/lookups/latlon.rb
|
|
76
80
|
- lib/geocoder/lookups/location_iq.rb
|
|
77
81
|
- lib/geocoder/lookups/mapbox.rb
|
|
78
82
|
- lib/geocoder/lookups/mapquest.rb
|
|
79
|
-
- lib/geocoder/lookups/mapzen.rb
|
|
80
83
|
- lib/geocoder/lookups/maxmind.rb
|
|
81
84
|
- lib/geocoder/lookups/maxmind_geoip2.rb
|
|
82
85
|
- lib/geocoder/lookups/maxmind_local.rb
|
|
86
|
+
- lib/geocoder/lookups/nationaal_georegister_nl.rb
|
|
83
87
|
- lib/geocoder/lookups/nominatim.rb
|
|
84
|
-
- lib/geocoder/lookups/okf.rb
|
|
85
88
|
- lib/geocoder/lookups/opencagedata.rb
|
|
86
|
-
- lib/geocoder/lookups/
|
|
89
|
+
- lib/geocoder/lookups/osmnames.rb
|
|
87
90
|
- lib/geocoder/lookups/pelias.rb
|
|
88
91
|
- lib/geocoder/lookups/pickpoint.rb
|
|
89
92
|
- lib/geocoder/lookups/pointpin.rb
|
|
@@ -91,7 +94,9 @@ files:
|
|
|
91
94
|
- lib/geocoder/lookups/postcodes_io.rb
|
|
92
95
|
- lib/geocoder/lookups/smarty_streets.rb
|
|
93
96
|
- lib/geocoder/lookups/telize.rb
|
|
97
|
+
- lib/geocoder/lookups/tencent.rb
|
|
94
98
|
- lib/geocoder/lookups/test.rb
|
|
99
|
+
- lib/geocoder/lookups/uk_ordnance_survey_names.rb
|
|
95
100
|
- lib/geocoder/lookups/yandex.rb
|
|
96
101
|
- lib/geocoder/models/active_record.rb
|
|
97
102
|
- lib/geocoder/models/base.rb
|
|
@@ -101,6 +106,7 @@ files:
|
|
|
101
106
|
- lib/geocoder/query.rb
|
|
102
107
|
- lib/geocoder/railtie.rb
|
|
103
108
|
- lib/geocoder/request.rb
|
|
109
|
+
- lib/geocoder/results/abstract_api.rb
|
|
104
110
|
- lib/geocoder/results/amap.rb
|
|
105
111
|
- lib/geocoder/results/baidu.rb
|
|
106
112
|
- lib/geocoder/results/baidu_ip.rb
|
|
@@ -112,7 +118,6 @@ files:
|
|
|
112
118
|
- lib/geocoder/results/esri.rb
|
|
113
119
|
- lib/geocoder/results/freegeoip.rb
|
|
114
120
|
- lib/geocoder/results/geocoder_ca.rb
|
|
115
|
-
- lib/geocoder/results/geocoder_us.rb
|
|
116
121
|
- lib/geocoder/results/geocodio.rb
|
|
117
122
|
- lib/geocoder/results/geoip2.rb
|
|
118
123
|
- lib/geocoder/results/geoportail_lu.rb
|
|
@@ -121,22 +126,24 @@ files:
|
|
|
121
126
|
- lib/geocoder/results/google_places_search.rb
|
|
122
127
|
- lib/geocoder/results/google_premier.rb
|
|
123
128
|
- lib/geocoder/results/here.rb
|
|
129
|
+
- lib/geocoder/results/ip2location.rb
|
|
124
130
|
- lib/geocoder/results/ipapi_com.rb
|
|
125
131
|
- lib/geocoder/results/ipdata_co.rb
|
|
132
|
+
- lib/geocoder/results/ipgeolocation.rb
|
|
126
133
|
- lib/geocoder/results/ipinfo_io.rb
|
|
134
|
+
- lib/geocoder/results/ipregistry.rb
|
|
127
135
|
- lib/geocoder/results/ipstack.rb
|
|
128
136
|
- lib/geocoder/results/latlon.rb
|
|
129
137
|
- lib/geocoder/results/location_iq.rb
|
|
130
138
|
- lib/geocoder/results/mapbox.rb
|
|
131
139
|
- lib/geocoder/results/mapquest.rb
|
|
132
|
-
- lib/geocoder/results/mapzen.rb
|
|
133
140
|
- lib/geocoder/results/maxmind.rb
|
|
134
141
|
- lib/geocoder/results/maxmind_geoip2.rb
|
|
135
142
|
- lib/geocoder/results/maxmind_local.rb
|
|
143
|
+
- lib/geocoder/results/nationaal_georegister_nl.rb
|
|
136
144
|
- lib/geocoder/results/nominatim.rb
|
|
137
|
-
- lib/geocoder/results/okf.rb
|
|
138
145
|
- lib/geocoder/results/opencagedata.rb
|
|
139
|
-
- lib/geocoder/results/
|
|
146
|
+
- lib/geocoder/results/osmnames.rb
|
|
140
147
|
- lib/geocoder/results/pelias.rb
|
|
141
148
|
- lib/geocoder/results/pickpoint.rb
|
|
142
149
|
- lib/geocoder/results/pointpin.rb
|
|
@@ -144,7 +151,9 @@ files:
|
|
|
144
151
|
- lib/geocoder/results/postcodes_io.rb
|
|
145
152
|
- lib/geocoder/results/smarty_streets.rb
|
|
146
153
|
- lib/geocoder/results/telize.rb
|
|
154
|
+
- lib/geocoder/results/tencent.rb
|
|
147
155
|
- lib/geocoder/results/test.rb
|
|
156
|
+
- lib/geocoder/results/uk_ordnance_survey_names.rb
|
|
148
157
|
- lib/geocoder/results/yandex.rb
|
|
149
158
|
- lib/geocoder/sql.rb
|
|
150
159
|
- lib/geocoder/stores/active_record.rb
|
|
@@ -152,8 +161,8 @@ files:
|
|
|
152
161
|
- lib/geocoder/stores/mongo_base.rb
|
|
153
162
|
- lib/geocoder/stores/mongo_mapper.rb
|
|
154
163
|
- lib/geocoder/stores/mongoid.rb
|
|
164
|
+
- lib/geocoder/util.rb
|
|
155
165
|
- lib/geocoder/version.rb
|
|
156
|
-
- lib/hash_recursive_merge.rb
|
|
157
166
|
- lib/maxmind_database.rb
|
|
158
167
|
- lib/tasks/geocoder.rake
|
|
159
168
|
- lib/tasks/maxmind.rake
|
|
@@ -163,11 +172,7 @@ licenses:
|
|
|
163
172
|
metadata:
|
|
164
173
|
source_code_uri: https://github.com/alexreisner/geocoder
|
|
165
174
|
changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
|
|
166
|
-
post_install_message:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
NOTE: Geocoder's default IP address lookup has changed from FreeGeoIP.net to IPInfo.io. If you explicitly specify :freegeoip in your configuration you must choose a different IP lookup before FreeGeoIP is discontinued on July 1, 2018. If you do not explicitly specify :freegeoip you do not need to change anything.
|
|
170
|
-
|
|
175
|
+
post_install_message:
|
|
171
176
|
rdoc_options: []
|
|
172
177
|
require_paths:
|
|
173
178
|
- lib
|
|
@@ -175,15 +180,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
175
180
|
requirements:
|
|
176
181
|
- - ">="
|
|
177
182
|
- !ruby/object:Gem::Version
|
|
178
|
-
version:
|
|
183
|
+
version: 2.0.0
|
|
179
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
185
|
requirements:
|
|
181
186
|
- - ">="
|
|
182
187
|
- !ruby/object:Gem::Version
|
|
183
188
|
version: '0'
|
|
184
189
|
requirements: []
|
|
185
|
-
|
|
186
|
-
rubygems_version: 2.5.2
|
|
190
|
+
rubygems_version: 3.1.2
|
|
187
191
|
signing_key:
|
|
188
192
|
specification_version: 4
|
|
189
193
|
summary: Complete geocoding solution for Ruby.
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
require 'geocoder/lookups/base'
|
|
2
|
-
require "geocoder/results/geocoder_us"
|
|
3
|
-
|
|
4
|
-
module Geocoder::Lookup
|
|
5
|
-
class GeocoderUs < Base
|
|
6
|
-
|
|
7
|
-
def name
|
|
8
|
-
"Geocoder.us"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def supported_protocols
|
|
12
|
-
[:http]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def query_url(query)
|
|
16
|
-
if configuration.api_key
|
|
17
|
-
"#{protocol}://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query)
|
|
18
|
-
else
|
|
19
|
-
"#{protocol}://geocoder.us/service/csv/geocode?" + url_query_string(query)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def results(query)
|
|
26
|
-
return [] unless doc = fetch_data(query)
|
|
27
|
-
if doc[0].to_s =~ /^(\d+)\:/
|
|
28
|
-
return []
|
|
29
|
-
else
|
|
30
|
-
return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc]
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def query_url_params(query)
|
|
35
|
-
(query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def parse_raw_data(raw_data)
|
|
39
|
-
raw_data.chomp.split(',')
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'geocoder/lookups/pelias'
|
|
2
|
-
require 'geocoder/results/mapzen'
|
|
3
|
-
|
|
4
|
-
# https://mapzen.com/documentation/search/search/ for more information
|
|
5
|
-
module Geocoder::Lookup
|
|
6
|
-
class Mapzen < Pelias
|
|
7
|
-
def name
|
|
8
|
-
'Mapzen'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def endpoint
|
|
12
|
-
configuration[:endpoint] || 'search.mapzen.com'
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
data/lib/geocoder/lookups/okf.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
require 'geocoder/lookups/base'
|
|
2
|
-
require "geocoder/results/okf"
|
|
3
|
-
|
|
4
|
-
module Geocoder::Lookup
|
|
5
|
-
class Okf < Base
|
|
6
|
-
|
|
7
|
-
def name
|
|
8
|
-
"Okf"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def query_url(query)
|
|
12
|
-
"#{protocol}://data.okf.fi/gis/1/geocode/json?" + url_query_string(query)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private # ---------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
def valid_response?(response)
|
|
18
|
-
json = parse_json(response.body)
|
|
19
|
-
status = json["status"] if json
|
|
20
|
-
super(response) and ['OK', 'ZERO_RESULTS'].include?(status)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def results(query)
|
|
24
|
-
return [] unless doc = fetch_data(query)
|
|
25
|
-
case doc['status']; when "OK" # OK status implies >0 results
|
|
26
|
-
return doc['results']
|
|
27
|
-
end
|
|
28
|
-
return []
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def query_url_okf_params(query)
|
|
32
|
-
params = {
|
|
33
|
-
(query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
|
|
34
|
-
:sensor => "false",
|
|
35
|
-
:language => (query.language || configuration.language)
|
|
36
|
-
}
|
|
37
|
-
params
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def query_url_params(query)
|
|
41
|
-
query_url_okf_params(query).merge(super)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
data/lib/geocoder/lookups/ovi.rb
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'geocoder/lookups/base'
|
|
2
|
-
require 'geocoder/results/ovi'
|
|
3
|
-
|
|
4
|
-
module Geocoder::Lookup
|
|
5
|
-
class Ovi < Base
|
|
6
|
-
|
|
7
|
-
def name
|
|
8
|
-
"Ovi"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def required_api_key_parts
|
|
12
|
-
[]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def query_url(query)
|
|
16
|
-
"#{protocol}://lbs.ovi.com/search/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private # ---------------------------------------------------------------
|
|
20
|
-
|
|
21
|
-
def results(query)
|
|
22
|
-
return [] unless doc = fetch_data(query)
|
|
23
|
-
return [] unless doc['Response'] && doc['Response']['View']
|
|
24
|
-
if r=doc['Response']['View']
|
|
25
|
-
return [] if r.nil? || !r.is_a?(Array) || r.empty?
|
|
26
|
-
return r.first['Result']
|
|
27
|
-
end
|
|
28
|
-
[]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def query_url_params(query)
|
|
32
|
-
options = {
|
|
33
|
-
:gen=>1,
|
|
34
|
-
:app_id=>api_key,
|
|
35
|
-
:app_code=>api_code
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if query.reverse_geocode?
|
|
39
|
-
super.merge(options).merge(
|
|
40
|
-
:prox=>query.sanitized_text,
|
|
41
|
-
:mode=>:retrieveAddresses
|
|
42
|
-
)
|
|
43
|
-
else
|
|
44
|
-
super.merge(options).merge(
|
|
45
|
-
:searchtext=>query.sanitized_text
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def api_key
|
|
51
|
-
if a=configuration.api_key
|
|
52
|
-
return a.first if a.is_a?(Array)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def api_code
|
|
57
|
-
if a=configuration.api_key
|
|
58
|
-
return a.last if a.is_a?(Array)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'geocoder/results/base'
|
|
2
|
-
|
|
3
|
-
module Geocoder::Result
|
|
4
|
-
class GeocoderUs < Base
|
|
5
|
-
def coordinates
|
|
6
|
-
[@data[0].to_f, @data[1].to_f]
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def address(format = :full)
|
|
10
|
-
"#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def street_address
|
|
14
|
-
@data[2]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def city
|
|
18
|
-
@data[3]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def state
|
|
22
|
-
@data[4]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
alias_method :state_code, :state
|
|
26
|
-
|
|
27
|
-
def postal_code
|
|
28
|
-
@data[5]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def country
|
|
32
|
-
'United States'
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def country_code
|
|
36
|
-
'US'
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|