geocoder 1.2.9 → 1.3.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 +35 -0
- data/README.md +81 -25
- data/lib/generators/geocoder/config/templates/initializer.rb +15 -15
- data/lib/geocoder/calculations.rb +6 -3
- data/lib/geocoder/configuration.rb +3 -2
- data/lib/geocoder/exceptions.rb +5 -0
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +13 -21
- data/lib/geocoder/lookup.rb +6 -4
- data/lib/geocoder/lookups/baidu.rb +1 -1
- data/lib/geocoder/lookups/baidu_ip.rb +1 -1
- data/lib/geocoder/lookups/base.rb +13 -13
- data/lib/geocoder/lookups/geocoder_us.rb +6 -2
- data/lib/geocoder/lookups/geoip2.rb +10 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +9 -0
- data/lib/geocoder/lookups/mapbox.rb +53 -0
- data/lib/geocoder/lookups/maxmind_local.rb +1 -1
- data/lib/geocoder/lookups/telize.rb +10 -3
- data/lib/geocoder/lookups/yandex.rb +4 -0
- data/lib/geocoder/request.rb +1 -1
- data/lib/geocoder/results/esri.rb +22 -6
- data/lib/geocoder/results/geoip2.rb +12 -8
- data/lib/geocoder/results/geoportail_lu.rb +69 -0
- data/lib/geocoder/results/google.rb +8 -0
- data/lib/geocoder/results/mapbox.rb +55 -0
- data/lib/geocoder/results/mapquest.rb +4 -0
- data/lib/geocoder/results/pointpin.rb +0 -4
- data/lib/geocoder/stores/active_record.rb +16 -0
- data/lib/geocoder/stores/base.rb +0 -11
- data/lib/geocoder/stores/mongo_base.rb +0 -31
- data/lib/geocoder/version.rb +1 -1
- data/lib/geocoder.rb +1 -0
- data/lib/maxmind_database.rb +1 -1
- data/lib/tasks/geocoder.rake +12 -3
- metadata +8 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/geoportail_lu"
|
|
3
|
+
|
|
4
|
+
module Geocoder
|
|
5
|
+
module Lookup
|
|
6
|
+
class GeoportailLu < Base
|
|
7
|
+
|
|
8
|
+
def name
|
|
9
|
+
"Geoportail.lu"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def query_url(query)
|
|
13
|
+
url_base_path(query) + url_query_string(query)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def url_base_path(query)
|
|
19
|
+
query.reverse_geocode? ? reverse_geocode_url_base_path : search_url_base_path
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def search_url_base_path
|
|
23
|
+
"#{protocol}://api.geoportail.lu/geocoder/search?"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def reverse_geocode_url_base_path
|
|
27
|
+
"#{protocol}://api.geoportail.lu/geocoder/reverseGeocode?"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def query_url_geoportail_lu_params(query)
|
|
31
|
+
query.reverse_geocode? ? reverse_geocode_params(query) : search_params(query)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def search_params(query)
|
|
35
|
+
{
|
|
36
|
+
queryString: query.sanitized_text
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def reverse_geocode_params(query)
|
|
41
|
+
lat_lon = query.coordinates
|
|
42
|
+
{
|
|
43
|
+
lat: lat_lon.first,
|
|
44
|
+
lon: lat_lon.last
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def query_url_params(query)
|
|
49
|
+
query_url_geoportail_lu_params(query).merge(super)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def results(query)
|
|
53
|
+
return [] unless doc = fetch_data(query)
|
|
54
|
+
if doc['success'] == true
|
|
55
|
+
result = doc['results']
|
|
56
|
+
else
|
|
57
|
+
result = []
|
|
58
|
+
raise_error(Geocoder::Error) ||
|
|
59
|
+
warn("Geportail.lu Geocoding API error")
|
|
60
|
+
end
|
|
61
|
+
result
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -12,6 +12,15 @@ module Geocoder::Lookup
|
|
|
12
12
|
"http://maps.google.com/maps?q=#{coordinates.join(',')}"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def supported_protocols
|
|
16
|
+
# Google requires HTTPS if an API key is used.
|
|
17
|
+
if configuration.api_key
|
|
18
|
+
[:https]
|
|
19
|
+
else
|
|
20
|
+
[:http, :https]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
15
24
|
def query_url(query)
|
|
16
25
|
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query)
|
|
17
26
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/mapbox"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Mapbox < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Mapbox"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def query_url(query)
|
|
12
|
+
"#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{url_query_string(query)}.json?access_token=#{configuration.api_key}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private # ---------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
def results(query)
|
|
18
|
+
return [] unless data = fetch_data(query)
|
|
19
|
+
if data['features']
|
|
20
|
+
sort_relevant_feature(data['features'])
|
|
21
|
+
elsif data['message'] =~ /Invalid\sToken/
|
|
22
|
+
raise_error(Geocoder::InvalidApiKey, data['message'])
|
|
23
|
+
else
|
|
24
|
+
[]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def url_query_string(query)
|
|
29
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
|
|
30
|
+
if query.reverse_geocode?
|
|
31
|
+
lat,lon = query.coordinates
|
|
32
|
+
"#{CGI.escape lon},#{CGI.escape lat}"
|
|
33
|
+
else
|
|
34
|
+
CGI.escape query.text.to_s
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def dataset
|
|
39
|
+
configuration[:dataset] || "mapbox.places"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def supported_protocols
|
|
43
|
+
[:https]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def sort_relevant_feature(features)
|
|
47
|
+
# Sort by descending relevance; Favor original order for equal relevance (eg occurs for reverse geocoding)
|
|
48
|
+
features.sort_by do |feature|
|
|
49
|
+
[feature["relevance"],-features.index(feature)]
|
|
50
|
+
end.reverse
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -36,7 +36,7 @@ module Geocoder::Lookup
|
|
|
36
36
|
addr = IPAddr.new(query.text).to_i
|
|
37
37
|
q = "SELECT l.country, l.region, l.city, l.latitude, l.longitude
|
|
38
38
|
FROM maxmind_geolite_city_location l WHERE l.loc_id = (SELECT b.loc_id FROM maxmind_geolite_city_blocks b
|
|
39
|
-
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num
|
|
39
|
+
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num)"
|
|
40
40
|
format_result(q, [:country_name, :region_name, :city_name, :latitude, :longitude])
|
|
41
41
|
elsif configuration[:package] == :country
|
|
42
42
|
addr = IPAddr.new(query.text).to_i
|
|
@@ -8,13 +8,16 @@ module Geocoder::Lookup
|
|
|
8
8
|
"Telize"
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
["key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
11
15
|
def query_url(query)
|
|
12
|
-
"
|
|
16
|
+
"#{protocol}://telize-v1.p.mashape.com/geoip/#{query.sanitized_text}?mashape-key=#{api_key}"
|
|
13
17
|
end
|
|
14
18
|
|
|
15
|
-
# currently doesn't support HTTPS
|
|
16
19
|
def supported_protocols
|
|
17
|
-
[:
|
|
20
|
+
[:https]
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
private # ---------------------------------------------------------------
|
|
@@ -36,5 +39,9 @@ module Geocoder::Lookup
|
|
|
36
39
|
def reserved_result(ip)
|
|
37
40
|
{"message" => "Input string is not a valid IP address", "code" => 401}
|
|
38
41
|
end
|
|
42
|
+
|
|
43
|
+
def api_key
|
|
44
|
+
configuration.api_key
|
|
45
|
+
end
|
|
39
46
|
end
|
|
40
47
|
end
|
|
@@ -15,6 +15,10 @@ module Geocoder::Lookup
|
|
|
15
15
|
def query_url(query)
|
|
16
16
|
"#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query)
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
def supported_protocols
|
|
20
|
+
[:https]
|
|
21
|
+
end
|
|
18
22
|
|
|
19
23
|
private # ---------------------------------------------------------------
|
|
20
24
|
|
data/lib/geocoder/request.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Geocoder
|
|
|
17
17
|
# corresponding to the original client IP for any request sent
|
|
18
18
|
# through a non-whitelisted proxy.
|
|
19
19
|
def safe_location
|
|
20
|
-
@
|
|
20
|
+
@safe_location ||= Geocoder.search(ip, ip_address: true).first
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# There's a whole zoo of nonstandard headers added by various
|
|
@@ -4,12 +4,16 @@ module Geocoder::Result
|
|
|
4
4
|
class Esri < Base
|
|
5
5
|
|
|
6
6
|
def address
|
|
7
|
-
|
|
8
|
-
attributes[
|
|
7
|
+
address_key = reverse_geocode? ? 'Address' : 'Match_addr'
|
|
8
|
+
attributes[address_key]
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def city
|
|
12
|
-
|
|
12
|
+
if !reverse_geocode? && is_city?
|
|
13
|
+
place_name
|
|
14
|
+
else
|
|
15
|
+
attributes['City']
|
|
16
|
+
end
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
def state_code
|
|
@@ -19,8 +23,8 @@ module Geocoder::Result
|
|
|
19
23
|
alias_method :state, :state_code
|
|
20
24
|
|
|
21
25
|
def country
|
|
22
|
-
|
|
23
|
-
attributes[
|
|
26
|
+
country_key = reverse_geocode? ? "CountryCode" : "Country"
|
|
27
|
+
attributes[country_key]
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
alias_method :country_code, :country
|
|
@@ -29,6 +33,15 @@ module Geocoder::Result
|
|
|
29
33
|
attributes['Postal']
|
|
30
34
|
end
|
|
31
35
|
|
|
36
|
+
def place_name
|
|
37
|
+
place_name_key = reverse_geocode? ? "Address" : "PlaceName"
|
|
38
|
+
attributes[place_name_key]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def place_type
|
|
42
|
+
reverse_geocode? ? "Address" : attributes['Type']
|
|
43
|
+
end
|
|
44
|
+
|
|
32
45
|
def coordinates
|
|
33
46
|
[geometry["y"], geometry["x"]]
|
|
34
47
|
end
|
|
@@ -47,5 +60,8 @@ module Geocoder::Result
|
|
|
47
60
|
@data['locations'].nil?
|
|
48
61
|
end
|
|
49
62
|
|
|
63
|
+
def is_city?
|
|
64
|
+
['City', 'State Capital', 'National Capital'].include?(place_type)
|
|
65
|
+
end
|
|
50
66
|
end
|
|
51
|
-
end
|
|
67
|
+
end
|
|
@@ -13,35 +13,35 @@ module Geocoder
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def latitude
|
|
16
|
-
data.fetch('location',{}).fetch('latitude',0.0)
|
|
16
|
+
data.fetch('location', {}).fetch('latitude', 0.0)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def longitude
|
|
20
|
-
data.fetch('location',{}).fetch('longitude',0.0)
|
|
20
|
+
data.fetch('location', {}).fetch('longitude', 0.0)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def city
|
|
24
|
-
data.fetch('city', {}).fetch('names', {}).fetch(
|
|
24
|
+
data.fetch('city', {}).fetch('names', {}).fetch(locale, '')
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def state
|
|
28
|
-
data.fetch('subdivisions',[]).fetch(0,{}).fetch('names',{}).fetch(
|
|
28
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {}).fetch(locale, '')
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def state_code
|
|
32
|
-
data.fetch('subdivisions',[]).fetch(0,{}).fetch('iso_code','')
|
|
32
|
+
data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def country
|
|
36
|
-
data.fetch('country', {}).fetch('names',{}).fetch(
|
|
36
|
+
data.fetch('country', {}).fetch('names', {}).fetch(locale, '')
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def country_code
|
|
40
|
-
data.fetch('country',{}).fetch('iso_code','')
|
|
40
|
+
data.fetch('country', {}).fetch('iso_code', '')
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def postal_code
|
|
44
|
-
data.fetch('postal',{}).fetch('code','')
|
|
44
|
+
data.fetch('postal', {}).fetch('code', '')
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def self.response_attributes
|
|
@@ -59,6 +59,10 @@ module Geocoder
|
|
|
59
59
|
def data
|
|
60
60
|
@data.to_hash
|
|
61
61
|
end
|
|
62
|
+
|
|
63
|
+
def locale
|
|
64
|
+
@locale ||= Geocoder.config[:language].to_s
|
|
65
|
+
end
|
|
62
66
|
end
|
|
63
67
|
end
|
|
64
68
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
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).present?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def try_to_extract(key, nullable_hash)
|
|
66
|
+
nullable_hash.try(:[], key)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Mapbox < Base
|
|
5
|
+
|
|
6
|
+
def latitude
|
|
7
|
+
@latitude ||= @data["geometry"]["coordinates"].last.to_f
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def longitude
|
|
11
|
+
@longitude ||= @data["geometry"]["coordinates"].first.to_f
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def coordinates
|
|
15
|
+
[latitude, longitude]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def place_name
|
|
19
|
+
@data['text']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def street
|
|
23
|
+
@data['properties']['address']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def city
|
|
27
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /place/ }.compact.first
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def state
|
|
31
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /region/ }.compact.first
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
alias_method :state_code, :state
|
|
35
|
+
|
|
36
|
+
def postal_code
|
|
37
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def country
|
|
41
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /country/ }.compact.first
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
alias_method :country_code, :country
|
|
45
|
+
|
|
46
|
+
def neighborhood
|
|
47
|
+
@data['context'].map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def address
|
|
51
|
+
[place_name, street, city, state, postal_code, country].compact.join(", ")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
@@ -28,6 +28,11 @@ module Geocoder::Store
|
|
|
28
28
|
"OR #{table_name}.#{geocoder_options[:longitude]} IS NULL")
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
# scope: not-reverse geocoded objects
|
|
32
|
+
scope :not_reverse_geocoded, lambda {
|
|
33
|
+
where("#{table_name}.#{geocoder_options[:fetched_address]} IS NULL")
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
##
|
|
32
37
|
# Find all objects within a radius of the given location.
|
|
33
38
|
# Location may be either a string to geocode or an array of
|
|
@@ -251,6 +256,17 @@ module Geocoder::Store
|
|
|
251
256
|
end
|
|
252
257
|
end
|
|
253
258
|
|
|
259
|
+
##
|
|
260
|
+
# Get nearby geocoded objects.
|
|
261
|
+
# Takes the same options hash as the near class method (scope).
|
|
262
|
+
# Returns nil if the object is not geocoded.
|
|
263
|
+
#
|
|
264
|
+
def nearbys(radius = 20, options = {})
|
|
265
|
+
return nil unless geocoded?
|
|
266
|
+
options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
|
|
267
|
+
self.class.near(self, radius, options)
|
|
268
|
+
end
|
|
269
|
+
|
|
254
270
|
##
|
|
255
271
|
# Look up coordinates and assign to +latitude+ and +longitude+ attributes
|
|
256
272
|
# (or other as specified in +geocoded_by+). Returns coordinates (array).
|
data/lib/geocoder/stores/base.rb
CHANGED
|
@@ -55,17 +55,6 @@ module Geocoder
|
|
|
55
55
|
point, to_coordinates, options)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
##
|
|
59
|
-
# Get nearby geocoded objects.
|
|
60
|
-
# Takes the same options hash as the near class method (scope).
|
|
61
|
-
# Returns nil if the object is not geocoded.
|
|
62
|
-
#
|
|
63
|
-
def nearbys(radius = 20, options = {})
|
|
64
|
-
return nil unless geocoded?
|
|
65
|
-
options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
|
|
66
|
-
self.class.near(self, radius, options)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
58
|
##
|
|
70
59
|
# Look up coordinates and assign to +latitude+ and +longitude+ attributes
|
|
71
60
|
# (or other as specified in +geocoded_by+). Returns coordinates (array).
|
|
@@ -11,37 +11,6 @@ module Geocoder::Store
|
|
|
11
11
|
scope :not_geocoded, lambda {
|
|
12
12
|
where(geocoder_options[:coordinates] => nil)
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
scope :near, lambda{ |location, *args|
|
|
16
|
-
coords = Geocoder::Calculations.extract_coordinates(location)
|
|
17
|
-
|
|
18
|
-
# no results if no lat/lon given
|
|
19
|
-
return where(:id => false) unless coords.is_a?(Array)
|
|
20
|
-
|
|
21
|
-
radius = args.size > 0 ? args.shift : 20
|
|
22
|
-
options = args.size > 0 ? args.shift : {}
|
|
23
|
-
options[:units] ||= geocoder_options[:units]
|
|
24
|
-
|
|
25
|
-
# Use BSON::OrderedHash if Ruby's hashes are unordered.
|
|
26
|
-
# Conditions must be in order required by indexes (see mongo gem).
|
|
27
|
-
version = RUBY_VERSION.split('.').map { |i| i.to_i }
|
|
28
|
-
empty = version[0] < 2 && version[1] < 9 ? BSON::OrderedHash.new : {}
|
|
29
|
-
|
|
30
|
-
conds = empty.clone
|
|
31
|
-
field = geocoder_options[:coordinates]
|
|
32
|
-
conds[field] = empty.clone
|
|
33
|
-
conds[field]["$nearSphere"] = coords.reverse
|
|
34
|
-
|
|
35
|
-
if radius
|
|
36
|
-
conds[field]["$maxDistance"] = \
|
|
37
|
-
Geocoder::Calculations.distance_to_radians(radius, options[:units])
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
if obj = options[:exclude]
|
|
41
|
-
conds[:_id.ne] = obj.id
|
|
42
|
-
end
|
|
43
|
-
where(conds)
|
|
44
|
-
}
|
|
45
14
|
end
|
|
46
15
|
end
|
|
47
16
|
|
data/lib/geocoder/version.rb
CHANGED
data/lib/geocoder.rb
CHANGED
data/lib/maxmind_database.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Geocoder
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def insert(package, dir = "tmp")
|
|
24
|
-
data_files(package).each do |filepath,table|
|
|
24
|
+
data_files(package, dir).each do |filepath,table|
|
|
25
25
|
print "Resetting table #{table}..."
|
|
26
26
|
ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
|
|
27
27
|
puts "done"
|
data/lib/tasks/geocoder.rake
CHANGED
|
@@ -4,13 +4,22 @@ namespace :geocode do
|
|
|
4
4
|
class_name = ENV['CLASS'] || ENV['class']
|
|
5
5
|
sleep_timer = ENV['SLEEP'] || ENV['sleep']
|
|
6
6
|
batch = ENV['BATCH'] || ENV['batch']
|
|
7
|
+
reverse = ENV['REVERSE'] || ENV['reverse']
|
|
7
8
|
raise "Please specify a CLASS (model)" unless class_name
|
|
8
9
|
klass = class_from_string(class_name)
|
|
9
10
|
batch = batch.to_i unless batch.nil?
|
|
11
|
+
reverse = false unless reverse.to_s.downcase == 'true'
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
if reverse
|
|
14
|
+
klass.not_reverse_geocoded.find_each(batch_size: batch) do |obj|
|
|
15
|
+
obj.reverse_geocode; obj.save
|
|
16
|
+
sleep(sleep_timer.to_f) unless sleep_timer.nil?
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
klass.not_geocoded.find_each(batch_size: batch) do |obj|
|
|
20
|
+
obj.geocode; obj.save
|
|
21
|
+
sleep(sleep_timer.to_f) unless sleep_timer.nil?
|
|
22
|
+
end
|
|
14
23
|
end
|
|
15
24
|
end
|
|
16
25
|
end
|
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.3.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: 2016-01-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,
|
|
@@ -43,6 +43,7 @@ files:
|
|
|
43
43
|
- lib/geocoder/configuration_hash.rb
|
|
44
44
|
- lib/geocoder/exceptions.rb
|
|
45
45
|
- lib/geocoder/ip_address.rb
|
|
46
|
+
- lib/geocoder/kernel_logger.rb
|
|
46
47
|
- lib/geocoder/logger.rb
|
|
47
48
|
- lib/geocoder/lookup.rb
|
|
48
49
|
- lib/geocoder/lookups/baidu.rb
|
|
@@ -56,10 +57,12 @@ files:
|
|
|
56
57
|
- lib/geocoder/lookups/geocoder_us.rb
|
|
57
58
|
- lib/geocoder/lookups/geocodio.rb
|
|
58
59
|
- lib/geocoder/lookups/geoip2.rb
|
|
60
|
+
- lib/geocoder/lookups/geoportail_lu.rb
|
|
59
61
|
- lib/geocoder/lookups/google.rb
|
|
60
62
|
- lib/geocoder/lookups/google_places_details.rb
|
|
61
63
|
- lib/geocoder/lookups/google_premier.rb
|
|
62
64
|
- lib/geocoder/lookups/here.rb
|
|
65
|
+
- lib/geocoder/lookups/mapbox.rb
|
|
63
66
|
- lib/geocoder/lookups/mapquest.rb
|
|
64
67
|
- lib/geocoder/lookups/maxmind.rb
|
|
65
68
|
- lib/geocoder/lookups/maxmind_geoip2.rb
|
|
@@ -94,10 +97,12 @@ files:
|
|
|
94
97
|
- lib/geocoder/results/geocoder_us.rb
|
|
95
98
|
- lib/geocoder/results/geocodio.rb
|
|
96
99
|
- lib/geocoder/results/geoip2.rb
|
|
100
|
+
- lib/geocoder/results/geoportail_lu.rb
|
|
97
101
|
- lib/geocoder/results/google.rb
|
|
98
102
|
- lib/geocoder/results/google_places_details.rb
|
|
99
103
|
- lib/geocoder/results/google_premier.rb
|
|
100
104
|
- lib/geocoder/results/here.rb
|
|
105
|
+
- lib/geocoder/results/mapbox.rb
|
|
101
106
|
- lib/geocoder/results/mapquest.rb
|
|
102
107
|
- lib/geocoder/results/maxmind.rb
|
|
103
108
|
- lib/geocoder/results/maxmind_geoip2.rb
|
|
@@ -145,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
145
150
|
version: '0'
|
|
146
151
|
requirements: []
|
|
147
152
|
rubyforge_project:
|
|
148
|
-
rubygems_version: 2.
|
|
153
|
+
rubygems_version: 2.5.1
|
|
149
154
|
signing_key:
|
|
150
155
|
specification_version: 4
|
|
151
156
|
summary: Complete geocoding solution for Ruby.
|