geocoder 1.4.9 → 1.6.7
Sign up to get free protection for your applications and to get access to all the features.
- 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/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
|
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
|