geocoder 1.5.2 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/LICENSE +1 -1
- data/README.md +8 -10
- data/bin/console +13 -0
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/geocoder/configuration.rb +2 -1
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +2 -1
- data/lib/geocoder/lookup.rb +6 -3
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +14 -1
- data/lib/geocoder/lookups/esri.rb +6 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +8 -14
- data/lib/geocoder/lookups/google_places_search.rb +28 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/here.rb +7 -16
- data/lib/geocoder/lookups/ip2location.rb +5 -13
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/latlon.rb +1 -2
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -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/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +1 -2
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- 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/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 +3 -3
- metadata +17 -11
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- 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
|
|
@@ -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.4
|
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: 2020-10-06 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
|
@@ -59,7 +60,6 @@ files:
|
|
59
60
|
- lib/geocoder/lookups/esri.rb
|
60
61
|
- lib/geocoder/lookups/freegeoip.rb
|
61
62
|
- lib/geocoder/lookups/geocoder_ca.rb
|
62
|
-
- lib/geocoder/lookups/geocoder_us.rb
|
63
63
|
- lib/geocoder/lookups/geocodio.rb
|
64
64
|
- lib/geocoder/lookups/geoip2.rb
|
65
65
|
- lib/geocoder/lookups/geoportail_lu.rb
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/geocoder/lookups/ip2location.rb
|
72
72
|
- lib/geocoder/lookups/ipapi_com.rb
|
73
73
|
- lib/geocoder/lookups/ipdata_co.rb
|
74
|
+
- lib/geocoder/lookups/ipgeolocation.rb
|
74
75
|
- lib/geocoder/lookups/ipinfo_io.rb
|
75
76
|
- lib/geocoder/lookups/ipregistry.rb
|
76
77
|
- lib/geocoder/lookups/ipstack.rb
|
@@ -81,8 +82,10 @@ files:
|
|
81
82
|
- lib/geocoder/lookups/maxmind.rb
|
82
83
|
- lib/geocoder/lookups/maxmind_geoip2.rb
|
83
84
|
- lib/geocoder/lookups/maxmind_local.rb
|
85
|
+
- lib/geocoder/lookups/nationaal_georegister_nl.rb
|
84
86
|
- lib/geocoder/lookups/nominatim.rb
|
85
87
|
- lib/geocoder/lookups/opencagedata.rb
|
88
|
+
- lib/geocoder/lookups/osmnames.rb
|
86
89
|
- lib/geocoder/lookups/pelias.rb
|
87
90
|
- lib/geocoder/lookups/pickpoint.rb
|
88
91
|
- lib/geocoder/lookups/pointpin.rb
|
@@ -92,6 +95,7 @@ files:
|
|
92
95
|
- lib/geocoder/lookups/telize.rb
|
93
96
|
- lib/geocoder/lookups/tencent.rb
|
94
97
|
- lib/geocoder/lookups/test.rb
|
98
|
+
- lib/geocoder/lookups/uk_ordnance_survey_names.rb
|
95
99
|
- lib/geocoder/lookups/yandex.rb
|
96
100
|
- lib/geocoder/models/active_record.rb
|
97
101
|
- lib/geocoder/models/base.rb
|
@@ -112,7 +116,6 @@ files:
|
|
112
116
|
- lib/geocoder/results/esri.rb
|
113
117
|
- lib/geocoder/results/freegeoip.rb
|
114
118
|
- lib/geocoder/results/geocoder_ca.rb
|
115
|
-
- lib/geocoder/results/geocoder_us.rb
|
116
119
|
- lib/geocoder/results/geocodio.rb
|
117
120
|
- lib/geocoder/results/geoip2.rb
|
118
121
|
- lib/geocoder/results/geoportail_lu.rb
|
@@ -124,6 +127,7 @@ files:
|
|
124
127
|
- lib/geocoder/results/ip2location.rb
|
125
128
|
- lib/geocoder/results/ipapi_com.rb
|
126
129
|
- lib/geocoder/results/ipdata_co.rb
|
130
|
+
- lib/geocoder/results/ipgeolocation.rb
|
127
131
|
- lib/geocoder/results/ipinfo_io.rb
|
128
132
|
- lib/geocoder/results/ipregistry.rb
|
129
133
|
- lib/geocoder/results/ipstack.rb
|
@@ -134,8 +138,10 @@ files:
|
|
134
138
|
- lib/geocoder/results/maxmind.rb
|
135
139
|
- lib/geocoder/results/maxmind_geoip2.rb
|
136
140
|
- lib/geocoder/results/maxmind_local.rb
|
141
|
+
- lib/geocoder/results/nationaal_georegister_nl.rb
|
137
142
|
- lib/geocoder/results/nominatim.rb
|
138
143
|
- lib/geocoder/results/opencagedata.rb
|
144
|
+
- lib/geocoder/results/osmnames.rb
|
139
145
|
- lib/geocoder/results/pelias.rb
|
140
146
|
- lib/geocoder/results/pickpoint.rb
|
141
147
|
- lib/geocoder/results/pointpin.rb
|
@@ -145,6 +151,7 @@ files:
|
|
145
151
|
- lib/geocoder/results/telize.rb
|
146
152
|
- lib/geocoder/results/tencent.rb
|
147
153
|
- lib/geocoder/results/test.rb
|
154
|
+
- lib/geocoder/results/uk_ordnance_survey_names.rb
|
148
155
|
- lib/geocoder/results/yandex.rb
|
149
156
|
- lib/geocoder/sql.rb
|
150
157
|
- lib/geocoder/stores/active_record.rb
|
@@ -152,8 +159,8 @@ files:
|
|
152
159
|
- lib/geocoder/stores/mongo_base.rb
|
153
160
|
- lib/geocoder/stores/mongo_mapper.rb
|
154
161
|
- lib/geocoder/stores/mongoid.rb
|
162
|
+
- lib/geocoder/util.rb
|
155
163
|
- lib/geocoder/version.rb
|
156
|
-
- lib/hash_recursive_merge.rb
|
157
164
|
- lib/maxmind_database.rb
|
158
165
|
- lib/tasks/geocoder.rake
|
159
166
|
- lib/tasks/maxmind.rake
|
@@ -178,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
185
|
- !ruby/object:Gem::Version
|
179
186
|
version: '0'
|
180
187
|
requirements: []
|
181
|
-
|
182
|
-
rubygems_version: 2.7.6
|
188
|
+
rubygems_version: 3.1.2
|
183
189
|
signing_key:
|
184
190
|
specification_version: 4
|
185
191
|
summary: Complete geocoding solution for Ruby.
|
@@ -1,51 +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
|
-
private # ----------------------------------------------------------------
|
16
|
-
|
17
|
-
def base_query_url(query)
|
18
|
-
base_query_url_with_optional_key(configuration.api_key)
|
19
|
-
end
|
20
|
-
|
21
|
-
def cache_key(query)
|
22
|
-
base_query_url_with_optional_key(nil) + url_query_string(query)
|
23
|
-
end
|
24
|
-
|
25
|
-
def base_query_url_with_optional_key(key = nil)
|
26
|
-
base = "#{protocol}://"
|
27
|
-
if configuration.api_key
|
28
|
-
base << "#{configuration.api_key}@"
|
29
|
-
end
|
30
|
-
base + "geocoder.us/member/service/csv/geocode?"
|
31
|
-
end
|
32
|
-
|
33
|
-
def results(query)
|
34
|
-
return [] unless doc = fetch_data(query)
|
35
|
-
if doc[0].to_s =~ /^(\d+)\:/
|
36
|
-
return []
|
37
|
-
else
|
38
|
-
return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def query_url_params(query)
|
43
|
-
(query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super)
|
44
|
-
end
|
45
|
-
|
46
|
-
def parse_raw_data(raw_data)
|
47
|
-
raw_data.chomp.split(',')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
@@ -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
|
data/lib/hash_recursive_merge.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = Hash Recursive Merge
|
3
|
-
#
|
4
|
-
# Merges a Ruby Hash recursively, Also known as deep merge.
|
5
|
-
# Recursive version of Hash#merge and Hash#merge!.
|
6
|
-
#
|
7
|
-
# Category:: Ruby
|
8
|
-
# Package:: Hash
|
9
|
-
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
-
# Copyright:: 2007-2008 The Authors
|
11
|
-
# License:: MIT License
|
12
|
-
# Link:: http://www.simonecarletti.com/
|
13
|
-
# Source:: http://gist.github.com/gists/6391/
|
14
|
-
#
|
15
|
-
module HashRecursiveMerge
|
16
|
-
|
17
|
-
#
|
18
|
-
# Recursive version of Hash#merge!
|
19
|
-
#
|
20
|
-
# Adds the contents of +other_hash+ to +hsh+,
|
21
|
-
# merging entries in +hsh+ with duplicate keys with those from +other_hash+.
|
22
|
-
#
|
23
|
-
# Compared with Hash#merge!, this method supports nested hashes.
|
24
|
-
# When both +hsh+ and +other_hash+ contains an entry with the same key,
|
25
|
-
# it merges and returns the values from both arrays.
|
26
|
-
#
|
27
|
-
# h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
28
|
-
# h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
|
29
|
-
# h1.rmerge!(h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
|
30
|
-
#
|
31
|
-
# Simply using Hash#merge! would return
|
32
|
-
#
|
33
|
-
# h1.merge!(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
34
|
-
#
|
35
|
-
def rmerge!(other_hash)
|
36
|
-
merge!(other_hash) do |key, oldval, newval|
|
37
|
-
oldval.class == self.class ? oldval.rmerge!(newval) : newval
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Recursive version of Hash#merge
|
43
|
-
#
|
44
|
-
# Compared with Hash#merge!, this method supports nested hashes.
|
45
|
-
# When both +hsh+ and +other_hash+ contains an entry with the same key,
|
46
|
-
# it merges and returns the values from both arrays.
|
47
|
-
#
|
48
|
-
# Compared with Hash#merge, this method provides a different approch
|
49
|
-
# for merging nasted hashes.
|
50
|
-
# If the value of a given key is an Hash and both +other_hash+ abd +hsh
|
51
|
-
# includes the same key, the value is merged instead replaced with
|
52
|
-
# +other_hash+ value.
|
53
|
-
#
|
54
|
-
# h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
55
|
-
# h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
|
56
|
-
# h1.rmerge(h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
|
57
|
-
#
|
58
|
-
# Simply using Hash#merge would return
|
59
|
-
#
|
60
|
-
# h1.merge(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
|
61
|
-
#
|
62
|
-
def rmerge(other_hash)
|
63
|
-
r = {}
|
64
|
-
merge(other_hash) do |key, oldval, newval|
|
65
|
-
r[key] = oldval.class == self.class ? oldval.rmerge(newval) : newval
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
class Hash
|
73
|
-
include HashRecursiveMerge
|
74
|
-
end
|