geocoder 1.4.8 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of geocoder might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +31 -0
- data/LICENSE +1 -1
- data/README.md +355 -950
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +1 -1
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +1 -1
- data/lib/geocoder/exceptions.rb +1 -1
- data/lib/geocoder/ip_address.rb +14 -1
- data/lib/geocoder/lookup.rb +7 -5
- 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 +17 -4
- 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 +39 -29
- 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 +8 -8
- 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 +10 -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 +63 -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 +4 -4
- 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/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 +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +20 -10
- data/lib/geocoder/lookups/telize.rb +23 -3
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +6 -6
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +0 -5
- data/lib/geocoder/results/freegeoip.rb +0 -5
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geoip2.rb +4 -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 +308 -0
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/postcodes_io.rb +40 -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/stores/active_record.rb +1 -3
- data/lib/geocoder/version.rb +1 -1
- data/lib/hash_recursive_merge.rb +1 -2
- data/lib/maxmind_database.rb +3 -3
- metadata +17 -18
- 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
@@ -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
|
data/lib/geocoder/results/okf.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'geocoder/results/base'
|
2
|
-
|
3
|
-
module Geocoder::Result
|
4
|
-
class Okf < 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 city
|
15
|
-
fields = [:locality, :sublocality,
|
16
|
-
:administrative_area_level_3,
|
17
|
-
:administrative_area_level_2]
|
18
|
-
fields.each do |f|
|
19
|
-
if entity = address_components_of_type(f).first
|
20
|
-
return entity['long_name']
|
21
|
-
end
|
22
|
-
end
|
23
|
-
return nil # no appropriate components found
|
24
|
-
end
|
25
|
-
|
26
|
-
def state
|
27
|
-
""
|
28
|
-
end
|
29
|
-
|
30
|
-
def sub_state
|
31
|
-
""
|
32
|
-
end
|
33
|
-
|
34
|
-
def state_code
|
35
|
-
""
|
36
|
-
end
|
37
|
-
|
38
|
-
def country
|
39
|
-
if country = address_components_of_type(:country).first
|
40
|
-
country['long_name']
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def country_code
|
45
|
-
if country = address_components_of_type(:country).first
|
46
|
-
country['short_name']
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def postal_code
|
51
|
-
if postal = address_components_of_type(:postal_code).first
|
52
|
-
postal['long_name']
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def route
|
57
|
-
if route = address_components_of_type(:route).first
|
58
|
-
route['long_name']
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def street_number
|
63
|
-
if street_number = address_components_of_type(:street_number).first
|
64
|
-
street_number['long_name']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def street_address
|
69
|
-
[route, street_number].compact.join(' ')
|
70
|
-
end
|
71
|
-
|
72
|
-
def types
|
73
|
-
@data['types']
|
74
|
-
end
|
75
|
-
|
76
|
-
def formatted_address
|
77
|
-
@data['formatted_address']
|
78
|
-
end
|
79
|
-
|
80
|
-
def address_components
|
81
|
-
@data['address_components']
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# Get address components of a given type. Valid types are defined in
|
86
|
-
# Google's Geocoding API documentation and include (among others):
|
87
|
-
#
|
88
|
-
# :street_number
|
89
|
-
# :locality
|
90
|
-
# :neighborhood
|
91
|
-
# :route
|
92
|
-
# :postal_code
|
93
|
-
#
|
94
|
-
def address_components_of_type(type)
|
95
|
-
address_components.select{ |c| c['types'].include?(type.to_s) }
|
96
|
-
end
|
97
|
-
|
98
|
-
def geometry
|
99
|
-
@data['geometry']
|
100
|
-
end
|
101
|
-
|
102
|
-
def precision
|
103
|
-
geometry['location_type'] if geometry
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/geocoder/results/ovi.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'geocoder/results/base'
|
2
|
-
|
3
|
-
module Geocoder::Result
|
4
|
-
class Ovi < Base
|
5
|
-
|
6
|
-
##
|
7
|
-
# A string in the given format.
|
8
|
-
#
|
9
|
-
def address(format = :full)
|
10
|
-
address_data['Label']
|
11
|
-
end
|
12
|
-
|
13
|
-
##
|
14
|
-
# A two-element array: [lat, lon].
|
15
|
-
#
|
16
|
-
def coordinates
|
17
|
-
fail unless d = @data['Location']['DisplayPosition']
|
18
|
-
[d['Latitude'].to_f, d['Longitude'].to_f]
|
19
|
-
end
|
20
|
-
|
21
|
-
def state
|
22
|
-
address_data['County']
|
23
|
-
end
|
24
|
-
|
25
|
-
def province
|
26
|
-
address_data['County']
|
27
|
-
end
|
28
|
-
|
29
|
-
def postal_code
|
30
|
-
address_data['PostalCode']
|
31
|
-
end
|
32
|
-
|
33
|
-
def city
|
34
|
-
address_data['City']
|
35
|
-
end
|
36
|
-
|
37
|
-
def state_code
|
38
|
-
address_data['State']
|
39
|
-
end
|
40
|
-
|
41
|
-
def province_code
|
42
|
-
address_data['State']
|
43
|
-
end
|
44
|
-
|
45
|
-
def country
|
46
|
-
fail unless d = address_data['AdditionalData']
|
47
|
-
if v = d.find{|ad| ad['key']=='CountryName'}
|
48
|
-
return v['value']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def country_code
|
53
|
-
address_data['Country']
|
54
|
-
end
|
55
|
-
|
56
|
-
def viewport
|
57
|
-
map_view = data['Location']['MapView'] || fail
|
58
|
-
south = map_view['BottomRight']['Latitude']
|
59
|
-
west = map_view['TopLeft']['Longitude']
|
60
|
-
north = map_view['TopLeft']['Latitude']
|
61
|
-
east = map_view['BottomRight']['Longitude']
|
62
|
-
[south, west, north, east]
|
63
|
-
end
|
64
|
-
|
65
|
-
private # ----------------------------------------------------------------
|
66
|
-
|
67
|
-
def address_data
|
68
|
-
@data['Location']['Address'] || fail
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|