geocoder 1.5.0 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +29 -2
- data/LICENSE +1 -1
- data/README.md +15 -17
- data/bin/console +7 -0
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/ip_address.rb +13 -0
- data/lib/geocoder/lookup.rb +8 -4
- data/lib/geocoder/lookups/baidu_ip.rb +1 -1
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +13 -0
- data/lib/geocoder/lookups/base.rb +7 -2
- data/lib/geocoder/lookups/bing.rb +2 -1
- data/lib/geocoder/lookups/esri.rb +38 -13
- data/lib/geocoder/lookups/freegeoip.rb +7 -7
- data/lib/geocoder/lookups/here.rb +28 -22
- data/lib/geocoder/lookups/ip2location.rb +7 -14
- data/lib/geocoder/lookups/ipapi_com.rb +2 -1
- data/lib/geocoder/lookups/ipdata_co.rb +5 -4
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +2 -11
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +2 -2
- data/lib/geocoder/lookups/maxmind.rb +2 -2
- data/lib/geocoder/lookups/maxmind_geoip2.rb +4 -7
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +2 -3
- data/lib/geocoder/lookups/pickpoint.rb +1 -1
- data/lib/geocoder/lookups/pointpin.rb +3 -3
- data/lib/geocoder/lookups/smarty_streets.rb +13 -3
- data/lib/geocoder/lookups/telize.rb +2 -2
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +2 -2
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/results/here.rb +4 -1
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipregistry.rb +308 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/smarty_streets.rb +48 -18
- data/lib/geocoder/results/tencent.rb +72 -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/stores/active_record.rb +1 -1
- data/lib/geocoder/version.rb +1 -1
- data/lib/hash_recursive_merge.rb +1 -2
- data/lib/maxmind_database.rb +3 -3
- metadata +18 -13
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/lookups/mapzen.rb +0 -15
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/mapzen.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90c4756998f02d1ff8f3f8ca4323d47e3d726547f8ce42c79fc21beeecd88b90
|
4
|
+
data.tar.gz: f2dc1c26391cd757001f2e973f4136e97c52da6f2153e9f3db29cae336555bdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43144700ad9a0a7fcec1dd0f363348b049984bda7fbefd57285c86a03ae7a16afc1302fd9dea656bc7b65142248d6cec06446f98dee80f9b5577b7ba4ee1b175
|
7
|
+
data.tar.gz: d4fcd8d3a6ed87234cdb9f411d7f58fd92d126f7ff23fef0c53e470ed78a76003f095a7b291c33748dd3e8282b2f237cf5c73e155863bb1d34b7e5f148e32677
|
data/CHANGELOG.md
CHANGED
@@ -3,10 +3,37 @@ Changelog
|
|
3
3
|
|
4
4
|
Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
|
5
5
|
|
6
|
-
1.
|
6
|
+
1.6.2 (2020 Mar 16)
|
7
7
|
-------------------
|
8
|
+
* Add support for :nationaal_georegister_nl lookup (thanks github.com/opensourceame).
|
9
|
+
* Add support for :uk_ordnance_survey_names lookup (thanks github.com/pezholio).
|
10
|
+
* Refactor and fix bugs in Yandex lookup (thanks github.com/iarie and stereodenis).
|
11
|
+
|
12
|
+
1.6.1 (2020 Jan 23)
|
13
|
+
-------------------
|
14
|
+
* Sanitize lat/lon values passed to within_bounding_box to prevent SQL injection.
|
15
|
+
|
16
|
+
1.6.0 (2020 Jan 6)
|
17
|
+
-------------------
|
18
|
+
* Drop support for Rails 3.x.
|
19
|
+
* Add support for :osmnames lookup (thanks github.com/zacviandier).
|
20
|
+
* Add support for :ipgeolocation IP lookup (thanks github.com/ahsannawaz111).
|
21
|
+
|
22
|
+
1.5.2 (2019 Oct 3)
|
23
|
+
-------------------
|
24
|
+
* Add support for :ipregistry lookup (thanks github.com/ipregistry).
|
25
|
+
* Various fixes for Yandex lookup.
|
26
|
+
|
27
|
+
1.5.1 (2019 Jan 23)
|
28
|
+
-------------------
|
29
|
+
* Add support for :tencent lookup (thanks github.com/Anders-E).
|
30
|
+
* Add support for :smarty_streets international API (thanks github.com/ankane).
|
31
|
+
* Remove :mapzen lookup.
|
32
|
+
|
33
|
+
1.5.0 (2018 Jul 31)
|
34
|
+
-------------------
|
35
|
+
* Drop support for Ruby <2.0.
|
8
36
|
* Change default street address lookup from :google to :nominatim.
|
9
|
-
* Drop support for Ruby 1.9.
|
10
37
|
* Cache keys no longer include API credentials. This means many entries in existing cache implementations will be invalidated.
|
11
38
|
* Test lookup fixtures should now return `coordinates` and NOT `latitude`/`longitude` attributes (see #1258). This may break some people's tests.
|
12
39
|
* Add support for :ip2location lookup (thanks github.com/ip2location).
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
Geocoder
|
2
2
|
========
|
3
3
|
|
4
|
-
**
|
4
|
+
**Complete geocoding solution for Ruby.**
|
5
5
|
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder)
|
8
8
|
[![Build Status](https://travis-ci.org/alexreisner/geocoder.svg?branch=master)](https://travis-ci.org/alexreisner/geocoder)
|
9
|
-
[![GitHub Issues](https://img.shields.io/github/issues/alexreisner/geocoder.svg)](https://github.com/alexreisner/geocoder/issues)
|
10
|
-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
11
9
|
|
12
10
|
Key features:
|
13
11
|
|
14
|
-
* Forward and reverse geocoding
|
12
|
+
* Forward and reverse geocoding.
|
13
|
+
* IP address geocoding.
|
15
14
|
* Connects to more than 40 APIs worldwide.
|
16
|
-
* Performance-enhancing
|
17
|
-
* Advanced configuration allows different parameters and APIs to be used in different conditions.
|
15
|
+
* Performance-enhancing features like caching.
|
18
16
|
* Integrates with ActiveRecord and Mongoid.
|
19
17
|
* Basic geospatial queries: search within radius (or rectangle, or ring).
|
20
18
|
|
21
19
|
Compatibility:
|
22
20
|
|
23
|
-
*
|
24
|
-
*
|
25
|
-
*
|
26
|
-
* Works
|
21
|
+
* Ruby versions: 2.x, and JRuby.
|
22
|
+
* Databases: MySQL, PostgreSQL, SQLite, and MongoDB.
|
23
|
+
* Rails: 4, 5, and 6.
|
24
|
+
* Works outside of Rails with the `json` (for MRI) or `json_pure` (for JRuby) gem.
|
27
25
|
|
28
26
|
|
29
27
|
Table of Contents
|
@@ -45,7 +43,7 @@ Advanced Features:
|
|
45
43
|
* [Geospatial Calculations](#geospatial-calculations)
|
46
44
|
* [Batch Geocoding](#batch-geocoding)
|
47
45
|
* [Testing](#testing)
|
48
|
-
* [Error Handling](#error-
|
46
|
+
* [Error Handling](#error-handling)
|
49
47
|
* [Command Line Interface](#command-line-interface)
|
50
48
|
|
51
49
|
The Rest:
|
@@ -224,15 +222,15 @@ Some common options are:
|
|
224
222
|
Please see [`lib/geocoder/configuration.rb`](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/configuration.rb) for a complete list of configuration options. Additionally, some lookups have their own special configuration options which are directly supported by Geocoder. For example, to specify a value for Google's `bounds` parameter:
|
225
223
|
|
226
224
|
# with Google:
|
227
|
-
Geocoder.search("
|
225
|
+
Geocoder.search("Middletown", bounds: [[40.6,-77.9], [39.9,-75.9]])
|
228
226
|
|
229
227
|
Please see the [source code for each lookup](https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups) to learn about directly supported parameters. Parameters which are not directly supported can be specified using the `:params` option, which appends options to the query string of the geocoding request. For example:
|
230
228
|
|
231
229
|
# Nominatim's `countrycodes` parameter:
|
232
|
-
Geocoder.search("
|
230
|
+
Geocoder.search("Rome", params: {countrycodes: "us,ca"})
|
233
231
|
|
234
232
|
# Google's `region` parameter:
|
235
|
-
Geocoder.search("
|
233
|
+
Geocoder.search("Rome", params: {region: "..."})
|
236
234
|
|
237
235
|
### Configuring Multiple Services
|
238
236
|
|
@@ -500,9 +498,9 @@ To avoid exceeding per-day limits you can add a `LIMIT` option. However, this wi
|
|
500
498
|
Testing
|
501
499
|
-------
|
502
500
|
|
503
|
-
When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup
|
501
|
+
When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup and/or `:ip_lookup`
|
504
502
|
|
505
|
-
Geocoder.configure(lookup: :test)
|
503
|
+
Geocoder.configure(lookup: :test, ip_lookup: :test)
|
506
504
|
|
507
505
|
Add stubs to define the results that will be returned:
|
508
506
|
|
@@ -703,4 +701,4 @@ For all contributions, please respect the following guidelines:
|
|
703
701
|
* If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release.
|
704
702
|
|
705
703
|
|
706
|
-
Copyright
|
704
|
+
Copyright :copyright: 2009-2020 Alex Reisner, released under the MIT license.
|
data/bin/console
ADDED
@@ -1,6 +1,8 @@
|
|
1
1
|
# This class implements a cache with simple delegation to the Redis store, but
|
2
2
|
# when it creates a key/value pair, it also sends an EXPIRE command with a TTL.
|
3
3
|
# It should be fairly simple to do the same thing with Memcached.
|
4
|
+
# Alternatively, this class could inherit from Redis, which would make most
|
5
|
+
# of the below methods unnecessary.
|
4
6
|
class AutoexpireCacheRedis
|
5
7
|
def initialize(store, ttl = 86400)
|
6
8
|
@store = store
|
@@ -0,0 +1,171 @@
|
|
1
|
+
module Geocoder
|
2
|
+
class EastingNorthing
|
3
|
+
attr_reader :easting, :northing, :lat_lng
|
4
|
+
|
5
|
+
def initialize(opts)
|
6
|
+
@easting = opts[:easting]
|
7
|
+
@northing = opts[:northing]
|
8
|
+
|
9
|
+
@lat_lng = to_WGS84(to_osgb_36)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def to_osgb_36
|
15
|
+
osgb_fo = 0.9996012717
|
16
|
+
northing0 = -100_000.0
|
17
|
+
easting0 = 400_000.0
|
18
|
+
phi0 = deg_to_rad(49.0)
|
19
|
+
lambda0 = deg_to_rad(-2.0)
|
20
|
+
a = 6_377_563.396
|
21
|
+
b = 6_356_256.909
|
22
|
+
eSquared = ((a * a) - (b * b)) / (a * a)
|
23
|
+
phi = 0.0
|
24
|
+
lambda = 0.0
|
25
|
+
n = (a - b) / (a + b)
|
26
|
+
m = 0.0
|
27
|
+
phiPrime = ((northing - northing0) / (a * osgb_fo)) + phi0
|
28
|
+
|
29
|
+
while (northing - northing0 - m) >= 0.001
|
30
|
+
m =
|
31
|
+
(b * osgb_fo)\
|
32
|
+
* (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n))\
|
33
|
+
* (phiPrime - phi0))\
|
34
|
+
- (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n))\
|
35
|
+
* Math.sin(phiPrime - phi0)\
|
36
|
+
* Math.cos(phiPrime + phi0))\
|
37
|
+
+ ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n))\
|
38
|
+
* Math.sin(2.0 * (phiPrime - phi0))\
|
39
|
+
* Math.cos(2.0 * (phiPrime + phi0)))\
|
40
|
+
- (((35.0 / 24.0) * n * n * n)\
|
41
|
+
* Math.sin(3.0 * (phiPrime - phi0))\
|
42
|
+
* Math.cos(3.0 * (phiPrime + phi0))))
|
43
|
+
|
44
|
+
phiPrime += (northing - northing0 - m) / (a * osgb_fo)
|
45
|
+
end
|
46
|
+
|
47
|
+
v = a * osgb_fo * ((1.0 - eSquared * sin_pow_2(phiPrime))**-0.5)
|
48
|
+
rho =
|
49
|
+
a\
|
50
|
+
* osgb_fo\
|
51
|
+
* (1.0 - eSquared)\
|
52
|
+
* ((1.0 - eSquared * sin_pow_2(phiPrime))**-1.5)
|
53
|
+
etaSquared = (v / rho) - 1.0
|
54
|
+
vii = Math.tan(phiPrime) / (2 * rho * v)
|
55
|
+
viii =
|
56
|
+
(Math.tan(phiPrime) / (24.0 * rho * (v**3.0)))\
|
57
|
+
* (5.0\
|
58
|
+
+ (3.0 * tan_pow_2(phiPrime))\
|
59
|
+
+ etaSquared\
|
60
|
+
- (9.0 * tan_pow_2(phiPrime) * etaSquared))
|
61
|
+
ix =
|
62
|
+
(Math.tan(phiPrime) / (720.0 * rho * (v**5.0)))\
|
63
|
+
* (61.0\
|
64
|
+
+ (90.0 * tan_pow_2(phiPrime))\
|
65
|
+
+ (45.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime)))
|
66
|
+
x = sec(phiPrime) / v
|
67
|
+
xi =
|
68
|
+
(sec(phiPrime) / (6.0 * v * v * v))\
|
69
|
+
* ((v / rho) + (2 * tan_pow_2(phiPrime)))
|
70
|
+
xiii =
|
71
|
+
(sec(phiPrime) / (120.0 * (v**5.0)))\
|
72
|
+
* (5.0\
|
73
|
+
+ (28.0 * tan_pow_2(phiPrime))\
|
74
|
+
+ (24.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime)))
|
75
|
+
xiia =
|
76
|
+
(sec(phiPrime) / (5040.0 * (v**7.0)))\
|
77
|
+
* (61.0\
|
78
|
+
+ (662.0 * tan_pow_2(phiPrime))\
|
79
|
+
+ (1320.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))\
|
80
|
+
+ (720.0\
|
81
|
+
* tan_pow_2(phiPrime)\
|
82
|
+
* tan_pow_2(phiPrime)\
|
83
|
+
* tan_pow_2(phiPrime)))
|
84
|
+
phi =
|
85
|
+
phiPrime\
|
86
|
+
- (vii * ((easting - easting0)**2.0))\
|
87
|
+
+ (viii * ((easting - easting0)**4.0))\
|
88
|
+
- (ix * ((easting - easting0)**6.0))
|
89
|
+
lambda =
|
90
|
+
lambda0\
|
91
|
+
+ (x * (easting - easting0))\
|
92
|
+
- (xi * ((easting - easting0)**3.0))\
|
93
|
+
+ (xiii * ((easting - easting0)**5.0))\
|
94
|
+
- (xiia * ((easting - easting0)**7.0))
|
95
|
+
|
96
|
+
[rad_to_deg(phi), rad_to_deg(lambda)]
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_WGS84(latlng)
|
100
|
+
latitude = latlng[0]
|
101
|
+
longitude = latlng[1]
|
102
|
+
|
103
|
+
a = 6_377_563.396
|
104
|
+
b = 6_356_256.909
|
105
|
+
eSquared = ((a * a) - (b * b)) / (a * a)
|
106
|
+
|
107
|
+
phi = deg_to_rad(latitude)
|
108
|
+
lambda = deg_to_rad(longitude)
|
109
|
+
v = a / Math.sqrt(1 - eSquared * sin_pow_2(phi))
|
110
|
+
h = 0
|
111
|
+
x = (v + h) * Math.cos(phi) * Math.cos(lambda)
|
112
|
+
y = (v + h) * Math.cos(phi) * Math.sin(lambda)
|
113
|
+
z = ((1 - eSquared) * v + h) * Math.sin(phi)
|
114
|
+
|
115
|
+
tx = 446.448
|
116
|
+
ty = -124.157
|
117
|
+
tz = 542.060
|
118
|
+
|
119
|
+
s = -0.0000204894
|
120
|
+
rx = deg_to_rad(0.00004172222)
|
121
|
+
ry = deg_to_rad(0.00006861111)
|
122
|
+
rz = deg_to_rad(0.00023391666)
|
123
|
+
|
124
|
+
xB = tx + (x * (1 + s)) + (-rx * y) + (ry * z)
|
125
|
+
yB = ty + (rz * x) + (y * (1 + s)) + (-rx * z)
|
126
|
+
zB = tz + (-ry * x) + (rx * y) + (z * (1 + s))
|
127
|
+
|
128
|
+
a = 6_378_137.000
|
129
|
+
b = 6_356_752.3141
|
130
|
+
eSquared = ((a * a) - (b * b)) / (a * a)
|
131
|
+
|
132
|
+
lambdaB = rad_to_deg(Math.atan(yB / xB))
|
133
|
+
p = Math.sqrt((xB * xB) + (yB * yB))
|
134
|
+
phiN = Math.atan(zB / (p * (1 - eSquared)))
|
135
|
+
|
136
|
+
(1..10).each do |_i|
|
137
|
+
v = a / Math.sqrt(1 - eSquared * sin_pow_2(phiN))
|
138
|
+
phiN1 = Math.atan((zB + (eSquared * v * Math.sin(phiN))) / p)
|
139
|
+
phiN = phiN1
|
140
|
+
end
|
141
|
+
|
142
|
+
phiB = rad_to_deg(phiN)
|
143
|
+
|
144
|
+
[phiB, lambdaB]
|
145
|
+
end
|
146
|
+
|
147
|
+
def deg_to_rad(degrees)
|
148
|
+
degrees / 180.0 * Math::PI
|
149
|
+
end
|
150
|
+
|
151
|
+
def rad_to_deg(r)
|
152
|
+
(r / Math::PI) * 180
|
153
|
+
end
|
154
|
+
|
155
|
+
def sin_pow_2(x)
|
156
|
+
Math.sin(x) * Math.sin(x)
|
157
|
+
end
|
158
|
+
|
159
|
+
def cos_pow_2(x)
|
160
|
+
Math.cos(x) * Math.cos(x)
|
161
|
+
end
|
162
|
+
|
163
|
+
def tan_pow_2(x)
|
164
|
+
Math.tan(x) * Math.tan(x)
|
165
|
+
end
|
166
|
+
|
167
|
+
def sec(x)
|
168
|
+
1.0 / Math.cos(x)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -154,7 +154,7 @@ module Geocoder
|
|
154
154
|
# Translate a bearing (float) into a compass direction (string, eg "North").
|
155
155
|
#
|
156
156
|
def compass_point(bearing, points = COMPASS_POINTS)
|
157
|
-
seg_size = 360 / points.size
|
157
|
+
seg_size = 360.0 / points.size
|
158
158
|
points[((bearing + (seg_size / 2)) % 360) / seg_size]
|
159
159
|
end
|
160
160
|
|
data/lib/geocoder/ip_address.rb
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
require 'resolv'
|
2
2
|
module Geocoder
|
3
3
|
class IpAddress < String
|
4
|
+
PRIVATE_IPS = [
|
5
|
+
'10.0.0.0/8',
|
6
|
+
'172.16.0.0/12',
|
7
|
+
'192.168.0.0/16',
|
8
|
+
].map { |ip| IPAddr.new(ip) }.freeze
|
9
|
+
|
10
|
+
def internal?
|
11
|
+
loopback? || private?
|
12
|
+
end
|
4
13
|
|
5
14
|
def loopback?
|
6
15
|
valid? and !!(self == "0.0.0.0" or self.match(/\A127\./) or self == "::1")
|
7
16
|
end
|
8
17
|
|
18
|
+
def private?
|
19
|
+
valid? && PRIVATE_IPS.any? { |ip| ip.include?(self) }
|
20
|
+
end
|
21
|
+
|
9
22
|
def valid?
|
10
23
|
!!((self =~ Resolv::IPv4::Regex) || (self =~ Resolv::IPv6::Regex))
|
11
24
|
end
|
data/lib/geocoder/lookup.rb
CHANGED
@@ -32,17 +32,18 @@ module Geocoder
|
|
32
32
|
:google_places_search,
|
33
33
|
:bing,
|
34
34
|
:geocoder_ca,
|
35
|
-
:geocoder_us,
|
36
35
|
:yandex,
|
36
|
+
:nationaal_georegister_nl,
|
37
37
|
:nominatim,
|
38
38
|
:mapbox,
|
39
39
|
:mapquest,
|
40
|
-
:
|
40
|
+
:uk_ordnance_survey_names,
|
41
41
|
:opencagedata,
|
42
42
|
:pelias,
|
43
43
|
:pickpoint,
|
44
44
|
:here,
|
45
45
|
:baidu,
|
46
|
+
:tencent,
|
46
47
|
:geocodio,
|
47
48
|
:smarty_streets,
|
48
49
|
:postcode_anywhere_uk,
|
@@ -51,7 +52,8 @@ module Geocoder
|
|
51
52
|
:ban_data_gouv_fr,
|
52
53
|
:test,
|
53
54
|
:latlon,
|
54
|
-
:amap
|
55
|
+
:amap,
|
56
|
+
:osmnames
|
55
57
|
]
|
56
58
|
end
|
57
59
|
|
@@ -69,11 +71,13 @@ module Geocoder
|
|
69
71
|
:pointpin,
|
70
72
|
:maxmind_geoip2,
|
71
73
|
:ipinfo_io,
|
74
|
+
:ipregistry,
|
72
75
|
:ipapi_com,
|
73
76
|
:ipdata_co,
|
74
77
|
:db_ip_com,
|
75
78
|
:ipstack,
|
76
|
-
:ip2location
|
79
|
+
:ip2location,
|
80
|
+
:ipgeolocation
|
77
81
|
]
|
78
82
|
end
|
79
83
|
|
@@ -86,6 +86,12 @@ module Geocoder::Lookup
|
|
86
86
|
unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode)
|
87
87
|
params[:citycode] = citycode.to_s
|
88
88
|
end
|
89
|
+
unless (lat = query.options[:lat]).nil? || !latitude_is_valid?(lat)
|
90
|
+
params[:lat] = lat
|
91
|
+
end
|
92
|
+
unless (lon = query.options[:lon]).nil? || !longitude_is_valid?(lon)
|
93
|
+
params[:lon] = lon
|
94
|
+
end
|
89
95
|
params
|
90
96
|
end
|
91
97
|
|
@@ -126,5 +132,12 @@ module Geocoder::Lookup
|
|
126
132
|
(1..99999).include?(param.to_i)
|
127
133
|
end
|
128
134
|
|
135
|
+
def latitude_is_valid?(param)
|
136
|
+
param.to_f <= 90 && param.to_f >= -90
|
137
|
+
end
|
138
|
+
|
139
|
+
def longitude_is_valid?(param)
|
140
|
+
param.to_f <= 180 && param.to_f >= -180
|
141
|
+
end
|
129
142
|
end
|
130
143
|
end
|
@@ -164,7 +164,7 @@ module Geocoder
|
|
164
164
|
def cache_key_params(query)
|
165
165
|
# omit api_key and token because they may vary among requests
|
166
166
|
query_url_params(query).reject do |key,value|
|
167
|
-
key.to_s.match
|
167
|
+
key.to_s.match(/(key|token)/)
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -197,6 +197,8 @@ module Geocoder
|
|
197
197
|
raise_error(err) or Geocoder.log(:warn, "Geocoding API connection cannot be established.")
|
198
198
|
rescue Errno::ECONNREFUSED => err
|
199
199
|
raise_error(err) or Geocoder.log(:warn, "Geocoding API connection refused.")
|
200
|
+
rescue Geocoder::NetworkError => err
|
201
|
+
raise_error(err) or Geocoder.log(:warn, "Geocoding API connection is either unreacheable or reset by the peer")
|
200
202
|
rescue Timeout::Error => err
|
201
203
|
raise_error(err) or Geocoder.log(:warn, "Geocoding API not responding fast enough " +
|
202
204
|
"(use Geocoder.configure(:timeout => ...) to set limit).")
|
@@ -209,7 +211,10 @@ module Geocoder
|
|
209
211
|
JSON.parse(data)
|
210
212
|
end
|
211
213
|
rescue
|
212
|
-
raise_error(ResponseParseError.new(data))
|
214
|
+
unless raise_error(ResponseParseError.new(data))
|
215
|
+
Geocoder.log(:warn, "Geocoding API's response was not valid JSON")
|
216
|
+
Geocoder.log(:debug, "Raw response: #{data}")
|
217
|
+
end
|
213
218
|
end
|
214
219
|
|
215
220
|
##
|