geocoder 1.4.3 → 1.5.0
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 +4 -4
- data/CHANGELOG.md +43 -0
- data/README.md +364 -880
- data/examples/autoexpire_cache_redis.rb +3 -3
- data/lib/generators/geocoder/config/templates/initializer.rb +3 -2
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +1 -1
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +1 -1
- data/lib/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder/cache.rb +6 -2
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +2 -2
- data/lib/geocoder/exceptions.rb +1 -1
- data/lib/geocoder/ip_address.rb +1 -1
- data/lib/geocoder/lookup.rb +9 -4
- data/lib/geocoder/lookups/amap.rb +63 -0
- data/lib/geocoder/lookups/baidu.rb +14 -10
- data/lib/geocoder/lookups/baidu_ip.rb +6 -35
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +4 -4
- data/lib/geocoder/lookups/base.rb +22 -4
- data/lib/geocoder/lookups/bing.rb +13 -12
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +1 -16
- data/lib/geocoder/lookups/freegeoip.rb +11 -2
- data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
- data/lib/geocoder/lookups/geocoder_us.rb +17 -9
- data/lib/geocoder/lookups/geocodio.rb +5 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
- data/lib/geocoder/lookups/google.rb +13 -9
- data/lib/geocoder/lookups/google_places_details.rb +4 -4
- data/lib/geocoder/lookups/google_places_search.rb +4 -4
- data/lib/geocoder/lookups/google_premier.rb +11 -1
- data/lib/geocoder/lookups/here.rb +4 -4
- data/lib/geocoder/lookups/ip2location.rb +74 -0
- data/lib/geocoder/lookups/ipapi_com.rb +7 -12
- data/lib/geocoder/lookups/ipdata_co.rb +61 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +10 -19
- data/lib/geocoder/lookups/ipstack.rb +63 -0
- data/lib/geocoder/lookups/latlon.rb +4 -4
- data/lib/geocoder/lookups/location_iq.rb +26 -8
- data/lib/geocoder/lookups/mapbox.rb +12 -6
- data/lib/geocoder/lookups/mapquest.rb +4 -5
- data/lib/geocoder/lookups/maxmind.rb +4 -4
- data/lib/geocoder/lookups/maxmind_geoip2.rb +4 -0
- data/lib/geocoder/lookups/nominatim.rb +17 -5
- data/lib/geocoder/lookups/opencagedata.rb +7 -6
- data/lib/geocoder/lookups/pelias.rb +6 -6
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/lib/geocoder/lookups/pointpin.rb +7 -6
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +4 -5
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +8 -8
- data/lib/geocoder/lookups/telize.rb +24 -4
- data/lib/geocoder/lookups/yandex.rb +10 -6
- data/lib/geocoder/models/active_record.rb +4 -3
- data/lib/geocoder/request.rb +32 -0
- data/lib/geocoder/results/amap.rb +87 -0
- data/lib/geocoder/results/baidu.rb +10 -10
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/freegeoip.rb +0 -5
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geoip2.rb +24 -10
- data/lib/geocoder/results/geoportail_lu.rb +5 -3
- data/lib/geocoder/results/google.rb +16 -5
- data/lib/geocoder/results/here.rb +8 -0
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipdata_co.rb +40 -0
- data/lib/geocoder/results/ipstack.rb +60 -0
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/nominatim.rb +12 -0
- data/lib/geocoder/results/opencagedata.rb +12 -2
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +7 -1
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/test.rb +1 -1
- data/lib/geocoder/sql.rb +2 -2
- data/lib/geocoder/stores/active_record.rb +15 -4
- data/lib/geocoder/stores/base.rb +1 -2
- data/lib/geocoder/version.rb +1 -1
- data/lib/tasks/geocoder.rake +11 -3
- metadata +27 -10
- data/lib/geocoder/lookups/okf.rb +0 -44
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -71
|
@@ -3,10 +3,6 @@ require 'geocoder/results/base'
|
|
|
3
3
|
module Geocoder
|
|
4
4
|
module Result
|
|
5
5
|
class Geoip2 < Base
|
|
6
|
-
def address(format = :full)
|
|
7
|
-
s = state.to_s == '' ? '' : ", #{state_code}"
|
|
8
|
-
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
|
|
9
|
-
end
|
|
10
6
|
|
|
11
7
|
def coordinates
|
|
12
8
|
%w[latitude longitude].map do |l|
|
|
@@ -15,11 +11,15 @@ module Geocoder
|
|
|
15
11
|
end
|
|
16
12
|
|
|
17
13
|
def city
|
|
18
|
-
|
|
14
|
+
fetch_name(
|
|
15
|
+
data.fetch('city', {}).fetch('names', {})
|
|
16
|
+
)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
def state
|
|
22
|
-
|
|
20
|
+
fetch_name(
|
|
21
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {})
|
|
22
|
+
)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def state_code
|
|
@@ -27,7 +27,9 @@ module Geocoder
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def country
|
|
30
|
-
|
|
30
|
+
fetch_name(
|
|
31
|
+
data.fetch('country', {}).fetch('names', {})
|
|
32
|
+
)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def country_code
|
|
@@ -48,14 +50,26 @@ module Geocoder
|
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
def language=(l)
|
|
54
|
+
@language = l.to_s
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def language
|
|
58
|
+
@language ||= default_language
|
|
59
|
+
end
|
|
52
60
|
|
|
53
61
|
def data
|
|
54
62
|
@data.to_hash
|
|
55
63
|
end
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
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] || ''
|
|
59
73
|
end
|
|
60
74
|
end
|
|
61
75
|
end
|
|
@@ -59,11 +59,13 @@ module Geocoder::Result
|
|
|
59
59
|
private
|
|
60
60
|
|
|
61
61
|
def geolocalized?
|
|
62
|
-
try_to_extract('coordinates', geomlonlat)
|
|
62
|
+
!!try_to_extract('coordinates', geomlonlat)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
def try_to_extract(key,
|
|
66
|
-
|
|
65
|
+
def try_to_extract(key, hash)
|
|
66
|
+
if hash.is_a?(Hash) and hash.include?(key)
|
|
67
|
+
hash[key]
|
|
68
|
+
end
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
end
|
|
@@ -120,19 +120,30 @@ module Geocoder::Result
|
|
|
120
120
|
def precision
|
|
121
121
|
geometry['location_type'] if geometry
|
|
122
122
|
end
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
def partial_match
|
|
125
125
|
@data['partial_match']
|
|
126
126
|
end
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
def place_id
|
|
129
129
|
@data['place_id']
|
|
130
|
-
end
|
|
130
|
+
end
|
|
131
131
|
|
|
132
132
|
def viewport
|
|
133
133
|
viewport = geometry['viewport'] || fail
|
|
134
|
-
|
|
135
|
-
|
|
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] }
|
|
136
147
|
[south, west, north, east]
|
|
137
148
|
end
|
|
138
149
|
end
|
|
@@ -17,6 +17,14 @@ module Geocoder::Result
|
|
|
17
17
|
fail unless d = @data['Location']['DisplayPosition']
|
|
18
18
|
[d['Latitude'].to_f, d['Longitude'].to_f]
|
|
19
19
|
end
|
|
20
|
+
|
|
21
|
+
def route
|
|
22
|
+
address_data['Street']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def street_number
|
|
26
|
+
address_data['HouseNumber']
|
|
27
|
+
end
|
|
20
28
|
|
|
21
29
|
def state
|
|
22
30
|
address_data['County']
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Ip2location < Base
|
|
5
|
+
|
|
6
|
+
def address(format = :full)
|
|
7
|
+
"#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.response_attributes
|
|
11
|
+
%w[country_code country_name region_name city_name latitude longitude
|
|
12
|
+
zip_code time_zone isp domain net_speed idd_code area_code usage_type
|
|
13
|
+
weather_station_code weather_station_name mcc mnc mobile_brand elevation]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
response_attributes.each do |attr|
|
|
17
|
+
define_method attr do
|
|
18
|
+
@data[attr] || ""
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class IpdataCo < Base
|
|
5
|
+
|
|
6
|
+
def city
|
|
7
|
+
@data['city']
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def state
|
|
11
|
+
@data['region']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def state_code
|
|
15
|
+
@data['region_code']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def country
|
|
19
|
+
@data['country_name']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def country_code
|
|
23
|
+
@data['country_code']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def postal_code
|
|
27
|
+
@data['postal']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.response_attributes
|
|
31
|
+
%w[ip asn organisation currency currency_symbol calling_code flag time_zone is_eu]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
response_attributes.each do |a|
|
|
35
|
+
define_method a do
|
|
36
|
+
@data[a]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Ipstack < Base
|
|
5
|
+
|
|
6
|
+
def address(format = :full)
|
|
7
|
+
s = region_code.empty? ? "" : ", #{region_code}"
|
|
8
|
+
"#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def state
|
|
12
|
+
@data['region_name']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def state_code
|
|
16
|
+
@data['region_code']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def country
|
|
20
|
+
@data['country_name']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def postal_code
|
|
24
|
+
@data['zip'] || @data['zipcode'] || @data['zip_code']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.response_attributes
|
|
28
|
+
[
|
|
29
|
+
['ip', ''],
|
|
30
|
+
['hostname', ''],
|
|
31
|
+
['continent_code', ''],
|
|
32
|
+
['continent_name', ''],
|
|
33
|
+
['country_code', ''],
|
|
34
|
+
['country_name', ''],
|
|
35
|
+
['region_code', ''],
|
|
36
|
+
['region_name', ''],
|
|
37
|
+
['city', ''],
|
|
38
|
+
['zip', ''],
|
|
39
|
+
['latitude', 0],
|
|
40
|
+
['longitude', 0],
|
|
41
|
+
['location', {}],
|
|
42
|
+
['time_zone', {}],
|
|
43
|
+
['currency', {}],
|
|
44
|
+
['connection', {}],
|
|
45
|
+
['security', {}],
|
|
46
|
+
]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
response_attributes.each do |attr, default|
|
|
50
|
+
define_method attr do
|
|
51
|
+
@data[attr] || default
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def metro_code
|
|
56
|
+
Geocoder.log(:warn, "Ipstack does not implement `metro_code` in api results. Please discontinue use.")
|
|
57
|
+
0 # no longer implemented by ipstack
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -87,11 +87,6 @@ module Geocoder::Result
|
|
|
87
87
|
[data_hash[:latitude].to_f, data_hash[:longitude].to_f]
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
def address(format = :full)
|
|
91
|
-
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
|
92
|
-
"#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
|
|
93
|
-
end
|
|
94
|
-
|
|
95
90
|
def city
|
|
96
91
|
data_hash[:city_name]
|
|
97
92
|
end
|
|
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class MaxmindLocal < Base
|
|
5
5
|
|
|
6
|
-
def address(format = :full)
|
|
7
|
-
s = state.to_s == "" ? "" : ", #{state}"
|
|
8
|
-
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
6
|
def coordinates
|
|
12
7
|
[@data[:latitude], @data[:longitude]]
|
|
13
8
|
end
|
|
@@ -64,6 +64,18 @@ module Geocoder::Result
|
|
|
64
64
|
@data['address']['suburb']
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
def city_district
|
|
68
|
+
@data['address']['city_district']
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def state_district
|
|
72
|
+
@data['address']['state_district']
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def neighbourhood
|
|
76
|
+
@data['address']['neighbourhood']
|
|
77
|
+
end
|
|
78
|
+
|
|
67
79
|
def coordinates
|
|
68
80
|
[@data['lat'].to_f, @data['lon'].to_f]
|
|
69
81
|
end
|
|
@@ -36,12 +36,13 @@ module Geocoder::Result
|
|
|
36
36
|
@data['components']['village']
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
40
39
|
def state
|
|
41
40
|
@data['components']['state']
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
def state_code
|
|
44
|
+
@data['components']['state_code']
|
|
45
|
+
end
|
|
45
46
|
|
|
46
47
|
def postal_code
|
|
47
48
|
@data['components']['postcode'].to_s
|
|
@@ -74,6 +75,15 @@ module Geocoder::Result
|
|
|
74
75
|
[south, west, north, east]
|
|
75
76
|
end
|
|
76
77
|
|
|
78
|
+
def time_zone
|
|
79
|
+
# The OpenCage API documentation states that `annotations` is available
|
|
80
|
+
# "when possible" https://geocoder.opencagedata.com/api#annotations
|
|
81
|
+
@data
|
|
82
|
+
.fetch('annotations', {})
|
|
83
|
+
.fetch('timezone', {})
|
|
84
|
+
.fetch('name', nil)
|
|
85
|
+
end
|
|
86
|
+
|
|
77
87
|
def self.response_attributes
|
|
78
88
|
%w[boundingbox license
|
|
79
89
|
formatted stadium]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class PostcodesIo < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
[@data['latitude'].to_f, @data['longitude'].to_f]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def quality
|
|
11
|
+
@data['quality']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def postal_code
|
|
15
|
+
@data['postcode']
|
|
16
|
+
end
|
|
17
|
+
alias address postal_code
|
|
18
|
+
|
|
19
|
+
def city
|
|
20
|
+
@data['admin_ward']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def county
|
|
24
|
+
@data['admin_county']
|
|
25
|
+
end
|
|
26
|
+
alias state county
|
|
27
|
+
|
|
28
|
+
def state_code
|
|
29
|
+
@data['codes']['admin_county']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def country
|
|
33
|
+
'United Kingdom'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def country_code
|
|
37
|
+
'UK'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -3,9 +3,15 @@ require 'geocoder/lookups/base'
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class SmartyStreets < Base
|
|
5
5
|
def coordinates
|
|
6
|
-
%w(latitude longitude).map do |i|
|
|
6
|
+
result = %w(latitude longitude).map do |i|
|
|
7
7
|
zipcode_endpoint? ? zipcodes.first[i] : metadata[i]
|
|
8
8
|
end
|
|
9
|
+
|
|
10
|
+
if result.compact.empty?
|
|
11
|
+
nil
|
|
12
|
+
else
|
|
13
|
+
result
|
|
14
|
+
end
|
|
9
15
|
end
|
|
10
16
|
|
|
11
17
|
def address
|
|
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class Telize < Base
|
|
5
5
|
|
|
6
|
-
def address(format = :full)
|
|
7
|
-
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
|
8
|
-
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
6
|
def city
|
|
12
7
|
@data['city']
|
|
13
8
|
end
|
|
@@ -15,7 +15,7 @@ module Geocoder
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
%w[
|
|
18
|
+
%w[coordinates neighborhood city state state_code sub_state
|
|
19
19
|
sub_state_code province province_code postal_code country
|
|
20
20
|
country_code address street_address street_number route geometry].each do |attr|
|
|
21
21
|
add_result_attribute(attr)
|
data/lib/geocoder/sql.rb
CHANGED
|
@@ -47,8 +47,8 @@ module Geocoder
|
|
|
47
47
|
spans = "#{lat_attr} BETWEEN #{sw_lat} AND #{ne_lat} 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} AND 180 OR " +
|
|
51
|
+
"#{lon_attr} BETWEEN -180 AND #{ne_lng})"
|
|
52
52
|
else
|
|
53
53
|
spans + "#{lon_attr} BETWEEN #{sw_lng} AND #{ne_lng}"
|
|
54
54
|
end
|
|
@@ -87,8 +87,6 @@ module Geocoder::Store
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
private # ----------------------------------------------------------------
|
|
91
|
-
|
|
92
90
|
##
|
|
93
91
|
# Get options hash suitable for passing to ActiveRecord.find to get
|
|
94
92
|
# records within a radius (in kilometers) of the given point.
|
|
@@ -131,7 +129,11 @@ module Geocoder::Store
|
|
|
131
129
|
distance_column = options.fetch(:distance_column) { 'distance' }
|
|
132
130
|
bearing_column = options.fetch(:bearing_column) { 'bearing' }
|
|
133
131
|
|
|
134
|
-
|
|
132
|
+
# If radius is a DB column name, bounding box should include
|
|
133
|
+
# all rows within the maximum radius appearing in that column.
|
|
134
|
+
# Note: performance is dependent on variability of radii.
|
|
135
|
+
bb_radius = radius.is_a?(Symbol) ? maximum(radius) : radius
|
|
136
|
+
b = Geocoder::Calculations.bounding_box([latitude, longitude], bb_radius, options)
|
|
135
137
|
args = b + [
|
|
136
138
|
full_column_name(latitude_attribute),
|
|
137
139
|
full_column_name(longitude_attribute)
|
|
@@ -142,7 +144,16 @@ module Geocoder::Store
|
|
|
142
144
|
conditions = bounding_box_conditions
|
|
143
145
|
else
|
|
144
146
|
min_radius = options.fetch(:min_radius, 0).to_f
|
|
145
|
-
|
|
147
|
+
# if radius is a DB column name,
|
|
148
|
+
# find rows between min_radius and value in column
|
|
149
|
+
if radius.is_a?(Symbol)
|
|
150
|
+
c = "BETWEEN ? AND #{radius}"
|
|
151
|
+
a = [min_radius]
|
|
152
|
+
else
|
|
153
|
+
c = "BETWEEN ? AND ?"
|
|
154
|
+
a = [min_radius, radius]
|
|
155
|
+
end
|
|
156
|
+
conditions = [bounding_box_conditions + " AND (#{distance}) " + c] + a
|
|
146
157
|
end
|
|
147
158
|
{
|
|
148
159
|
:select => select_clause(options[:select],
|
data/lib/geocoder/stores/base.rb
CHANGED
|
@@ -90,7 +90,7 @@ module Geocoder
|
|
|
90
90
|
return
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
query_options = [:lookup, :ip_lookup, :language].inject({}) do |hash, key|
|
|
93
|
+
query_options = [:lookup, :ip_lookup, :language, :params].inject({}) do |hash, key|
|
|
94
94
|
if options.has_key?(key)
|
|
95
95
|
val = options[key]
|
|
96
96
|
hash[key] = val.respond_to?(:call) ? val.call(self) : val
|
|
@@ -113,4 +113,3 @@ module Geocoder
|
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
|
-
|
data/lib/geocoder/version.rb
CHANGED
data/lib/tasks/geocoder.rake
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "geocoder/models/mongoid"
|
|
1
|
+
require "geocoder/models/mongoid"
|
|
2
2
|
|
|
3
3
|
namespace :geocode do
|
|
4
4
|
desc "Geocode all objects without coordinates."
|
|
@@ -7,6 +7,7 @@ namespace :geocode do
|
|
|
7
7
|
sleep_timer = ENV['SLEEP'] || ENV['sleep']
|
|
8
8
|
batch = ENV['BATCH'] || ENV['batch']
|
|
9
9
|
reverse = ENV['REVERSE'] || ENV['reverse']
|
|
10
|
+
limit = ENV['LIMIT'] || ENV['limit']
|
|
10
11
|
raise "Please specify a CLASS (model)" unless class_name
|
|
11
12
|
klass = class_from_string(class_name)
|
|
12
13
|
batch = (batch.to_i unless batch.nil?) || 1000
|
|
@@ -20,13 +21,20 @@ namespace :geocode do
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
scope = reverse ? klass.not_reverse_geocoded : klass.not_geocoded
|
|
24
|
+
scope = scope.limit(limit) if limit
|
|
23
25
|
if orm == 'mongoid'
|
|
24
26
|
scope.each do |obj|
|
|
25
27
|
geocode_record.call(obj)
|
|
26
28
|
end
|
|
27
29
|
elsif orm == 'active_record'
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
if limit
|
|
31
|
+
scope.each do |obj|
|
|
32
|
+
geocode_record.call(obj)
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
scope.find_each(batch_size: batch) do |obj|
|
|
36
|
+
geocode_record.call(obj)
|
|
37
|
+
end
|
|
30
38
|
end
|
|
31
39
|
end
|
|
32
40
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: geocoder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
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: 2018-07-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Provides object geocoding (by street or IP address), reverse geocoding
|
|
14
14
|
(coordinates to street address), distance queries for ActiveRecord and Mongoid,
|
|
@@ -35,6 +35,7 @@ files:
|
|
|
35
35
|
- lib/generators/geocoder/maxmind/geolite_country_generator.rb
|
|
36
36
|
- lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb
|
|
37
37
|
- lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb
|
|
38
|
+
- lib/generators/geocoder/migration_version.rb
|
|
38
39
|
- lib/geocoder.rb
|
|
39
40
|
- lib/geocoder/cache.rb
|
|
40
41
|
- lib/geocoder/calculations.rb
|
|
@@ -47,11 +48,13 @@ files:
|
|
|
47
48
|
- lib/geocoder/kernel_logger.rb
|
|
48
49
|
- lib/geocoder/logger.rb
|
|
49
50
|
- lib/geocoder/lookup.rb
|
|
51
|
+
- lib/geocoder/lookups/amap.rb
|
|
50
52
|
- lib/geocoder/lookups/baidu.rb
|
|
51
53
|
- lib/geocoder/lookups/baidu_ip.rb
|
|
52
54
|
- lib/geocoder/lookups/ban_data_gouv_fr.rb
|
|
53
55
|
- lib/geocoder/lookups/base.rb
|
|
54
56
|
- lib/geocoder/lookups/bing.rb
|
|
57
|
+
- lib/geocoder/lookups/db_ip_com.rb
|
|
55
58
|
- lib/geocoder/lookups/dstk.rb
|
|
56
59
|
- lib/geocoder/lookups/esri.rb
|
|
57
60
|
- lib/geocoder/lookups/freegeoip.rb
|
|
@@ -65,8 +68,11 @@ files:
|
|
|
65
68
|
- lib/geocoder/lookups/google_places_search.rb
|
|
66
69
|
- lib/geocoder/lookups/google_premier.rb
|
|
67
70
|
- lib/geocoder/lookups/here.rb
|
|
71
|
+
- lib/geocoder/lookups/ip2location.rb
|
|
68
72
|
- lib/geocoder/lookups/ipapi_com.rb
|
|
73
|
+
- lib/geocoder/lookups/ipdata_co.rb
|
|
69
74
|
- lib/geocoder/lookups/ipinfo_io.rb
|
|
75
|
+
- lib/geocoder/lookups/ipstack.rb
|
|
70
76
|
- lib/geocoder/lookups/latlon.rb
|
|
71
77
|
- lib/geocoder/lookups/location_iq.rb
|
|
72
78
|
- lib/geocoder/lookups/mapbox.rb
|
|
@@ -76,12 +82,12 @@ files:
|
|
|
76
82
|
- lib/geocoder/lookups/maxmind_geoip2.rb
|
|
77
83
|
- lib/geocoder/lookups/maxmind_local.rb
|
|
78
84
|
- lib/geocoder/lookups/nominatim.rb
|
|
79
|
-
- lib/geocoder/lookups/okf.rb
|
|
80
85
|
- lib/geocoder/lookups/opencagedata.rb
|
|
81
|
-
- lib/geocoder/lookups/ovi.rb
|
|
82
86
|
- lib/geocoder/lookups/pelias.rb
|
|
87
|
+
- lib/geocoder/lookups/pickpoint.rb
|
|
83
88
|
- lib/geocoder/lookups/pointpin.rb
|
|
84
89
|
- lib/geocoder/lookups/postcode_anywhere_uk.rb
|
|
90
|
+
- lib/geocoder/lookups/postcodes_io.rb
|
|
85
91
|
- lib/geocoder/lookups/smarty_streets.rb
|
|
86
92
|
- lib/geocoder/lookups/telize.rb
|
|
87
93
|
- lib/geocoder/lookups/test.rb
|
|
@@ -94,11 +100,13 @@ files:
|
|
|
94
100
|
- lib/geocoder/query.rb
|
|
95
101
|
- lib/geocoder/railtie.rb
|
|
96
102
|
- lib/geocoder/request.rb
|
|
103
|
+
- lib/geocoder/results/amap.rb
|
|
97
104
|
- lib/geocoder/results/baidu.rb
|
|
98
105
|
- lib/geocoder/results/baidu_ip.rb
|
|
99
106
|
- lib/geocoder/results/ban_data_gouv_fr.rb
|
|
100
107
|
- lib/geocoder/results/base.rb
|
|
101
108
|
- lib/geocoder/results/bing.rb
|
|
109
|
+
- lib/geocoder/results/db_ip_com.rb
|
|
102
110
|
- lib/geocoder/results/dstk.rb
|
|
103
111
|
- lib/geocoder/results/esri.rb
|
|
104
112
|
- lib/geocoder/results/freegeoip.rb
|
|
@@ -112,8 +120,11 @@ files:
|
|
|
112
120
|
- lib/geocoder/results/google_places_search.rb
|
|
113
121
|
- lib/geocoder/results/google_premier.rb
|
|
114
122
|
- lib/geocoder/results/here.rb
|
|
123
|
+
- lib/geocoder/results/ip2location.rb
|
|
115
124
|
- lib/geocoder/results/ipapi_com.rb
|
|
125
|
+
- lib/geocoder/results/ipdata_co.rb
|
|
116
126
|
- lib/geocoder/results/ipinfo_io.rb
|
|
127
|
+
- lib/geocoder/results/ipstack.rb
|
|
117
128
|
- lib/geocoder/results/latlon.rb
|
|
118
129
|
- lib/geocoder/results/location_iq.rb
|
|
119
130
|
- lib/geocoder/results/mapbox.rb
|
|
@@ -123,12 +134,12 @@ files:
|
|
|
123
134
|
- lib/geocoder/results/maxmind_geoip2.rb
|
|
124
135
|
- lib/geocoder/results/maxmind_local.rb
|
|
125
136
|
- lib/geocoder/results/nominatim.rb
|
|
126
|
-
- lib/geocoder/results/okf.rb
|
|
127
137
|
- lib/geocoder/results/opencagedata.rb
|
|
128
|
-
- lib/geocoder/results/ovi.rb
|
|
129
138
|
- lib/geocoder/results/pelias.rb
|
|
139
|
+
- lib/geocoder/results/pickpoint.rb
|
|
130
140
|
- lib/geocoder/results/pointpin.rb
|
|
131
141
|
- lib/geocoder/results/postcode_anywhere_uk.rb
|
|
142
|
+
- lib/geocoder/results/postcodes_io.rb
|
|
132
143
|
- lib/geocoder/results/smarty_streets.rb
|
|
133
144
|
- lib/geocoder/results/telize.rb
|
|
134
145
|
- lib/geocoder/results/test.rb
|
|
@@ -147,8 +158,14 @@ files:
|
|
|
147
158
|
homepage: http://www.rubygeocoder.com
|
|
148
159
|
licenses:
|
|
149
160
|
- MIT
|
|
150
|
-
metadata:
|
|
151
|
-
|
|
161
|
+
metadata:
|
|
162
|
+
source_code_uri: https://github.com/alexreisner/geocoder
|
|
163
|
+
changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
|
|
164
|
+
post_install_message: |2+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
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.
|
|
168
|
+
|
|
152
169
|
rdoc_options: []
|
|
153
170
|
require_paths:
|
|
154
171
|
- lib
|
|
@@ -156,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
156
173
|
requirements:
|
|
157
174
|
- - ">="
|
|
158
175
|
- !ruby/object:Gem::Version
|
|
159
|
-
version:
|
|
176
|
+
version: 2.0.0
|
|
160
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
178
|
requirements:
|
|
162
179
|
- - ">="
|
|
@@ -164,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
164
181
|
version: '0'
|
|
165
182
|
requirements: []
|
|
166
183
|
rubyforge_project:
|
|
167
|
-
rubygems_version: 2.5.
|
|
184
|
+
rubygems_version: 2.5.2
|
|
168
185
|
signing_key:
|
|
169
186
|
specification_version: 4
|
|
170
187
|
summary: Complete geocoding solution for Ruby.
|