geocoder 1.1.9 → 1.2.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +9 -5
- data/CHANGELOG.md +19 -0
- data/README.md +175 -10
- data/Rakefile +1 -1
- data/gemfiles/Gemfile.mongoid-2.4.x +1 -0
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +28 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +28 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +27 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/lib/geocoder.rb +4 -12
- data/lib/geocoder/cache.rb +3 -2
- data/lib/geocoder/calculations.rb +39 -0
- data/lib/geocoder/configuration.rb +1 -7
- data/lib/geocoder/ip_address.rb +12 -0
- data/lib/geocoder/lookup.rb +10 -1
- data/lib/geocoder/lookups/baidu.rb +7 -6
- data/lib/geocoder/lookups/baidu_ip.rb +54 -0
- data/lib/geocoder/lookups/base.rb +37 -9
- data/lib/geocoder/lookups/bing.rb +10 -5
- data/lib/geocoder/lookups/cloudmade.rb +35 -0
- data/lib/geocoder/lookups/freegeoip.rb +5 -1
- data/lib/geocoder/lookups/geocodio.rb +42 -0
- data/lib/geocoder/lookups/google_premier.rb +1 -1
- data/lib/geocoder/lookups/here.rb +62 -0
- data/lib/geocoder/lookups/mapquest.rb +2 -1
- data/lib/geocoder/lookups/maxmind_local.rb +58 -0
- data/lib/geocoder/lookups/nominatim.rb +8 -0
- data/lib/geocoder/lookups/smarty_streets.rb +45 -0
- data/lib/geocoder/lookups/yahoo.rb +1 -1
- data/lib/geocoder/models/active_record.rb +5 -3
- data/lib/geocoder/models/base.rb +1 -4
- data/lib/geocoder/models/mongo_base.rb +4 -2
- data/lib/geocoder/query.rb +4 -4
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +10 -8
- data/lib/geocoder/results/baidu_ip.rb +62 -0
- data/lib/geocoder/results/cloudmade.rb +39 -0
- data/lib/geocoder/results/geocodio.rb +66 -0
- data/lib/geocoder/results/here.rb +62 -0
- data/lib/geocoder/results/maxmind_local.rb +49 -0
- data/lib/geocoder/results/smarty_streets.rb +106 -0
- data/lib/geocoder/results/test.rb +20 -3
- data/lib/geocoder/results/yandex.rb +7 -3
- data/lib/geocoder/sql.rb +16 -15
- data/lib/geocoder/stores/active_record.rb +6 -2
- data/lib/geocoder/stores/base.rb +8 -1
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +109 -0
- data/lib/oauth_util.rb +1 -1
- data/lib/tasks/geocoder.rake +3 -1
- data/lib/tasks/maxmind.rake +73 -0
- data/test/fixtures/baidu_ip_202_198_16_3 +19 -0
- data/test/fixtures/baidu_ip_invalid_key +1 -0
- data/test/fixtures/baidu_ip_no_results +1 -0
- data/test/fixtures/cloudmade_invalid_key +1 -0
- data/test/fixtures/cloudmade_madison_square_garden +1 -0
- data/test/fixtures/cloudmade_no_results +1 -0
- data/test/fixtures/geocodio_1101_pennsylvania_ave +1 -0
- data/test/fixtures/geocodio_bad_api_key +3 -0
- data/test/fixtures/geocodio_invalid +4 -0
- data/test/fixtures/geocodio_no_results +1 -0
- data/test/fixtures/geocodio_over_query_limit +4 -0
- data/test/fixtures/here_madison_square_garden +72 -0
- data/test/fixtures/here_no_results +8 -0
- data/test/fixtures/nominatim_over_limit +1 -0
- data/test/fixtures/smarty_streets_11211 +1 -0
- data/test/fixtures/smarty_streets_madison_square_garden +47 -0
- data/test/fixtures/smarty_streets_no_results +1 -0
- data/test/fixtures/yandex_canada_rue_dupuis_14 +446 -0
- data/test/fixtures/yandex_new_york +1 -0
- data/test/integration/http_client_test.rb +25 -0
- data/test/mongoid_test_helper.rb +2 -2
- data/test/test_helper.rb +98 -30
- data/test/{active_record_test.rb → unit/active_record_test.rb} +4 -3
- data/test/{cache_test.rb → unit/cache_test.rb} +3 -1
- data/test/{calculations_test.rb → unit/calculations_test.rb} +22 -13
- data/test/{configuration_test.rb → unit/configuration_test.rb} +4 -27
- data/test/{error_handling_test.rb → unit/error_handling_test.rb} +10 -9
- data/test/{geocoder_test.rb → unit/geocoder_test.rb} +26 -7
- data/test/{https_test.rb → unit/https_test.rb} +4 -3
- data/test/unit/ip_address_test.rb +24 -0
- data/test/{lookup_test.rb → unit/lookup_test.rb} +33 -20
- data/test/unit/lookups/bing_test.rb +68 -0
- data/test/unit/lookups/dstk_test.rb +26 -0
- data/test/unit/lookups/esri_test.rb +48 -0
- data/test/unit/lookups/freegeoip_test.rb +27 -0
- data/test/unit/lookups/geocoder_ca_test.rb +17 -0
- data/test/unit/lookups/geocodio_test.rb +55 -0
- data/test/unit/lookups/google_premier_test.rb +22 -0
- data/test/unit/lookups/google_test.rb +84 -0
- data/test/unit/lookups/mapquest_test.rb +60 -0
- data/test/unit/lookups/maxmind_local_test.rb +28 -0
- data/test/unit/lookups/maxmind_test.rb +63 -0
- data/test/unit/lookups/nominatim_test.rb +31 -0
- data/test/unit/lookups/smarty_streets_test.rb +71 -0
- data/test/unit/lookups/yahoo_test.rb +35 -0
- data/test/{method_aliases_test.rb → unit/method_aliases_test.rb} +5 -4
- data/test/unit/model_test.rb +38 -0
- data/test/{mongoid_test.rb → unit/mongoid_test.rb} +10 -9
- data/test/unit/near_test.rb +87 -0
- data/test/{oauth_util_test.rb → unit/oauth_util_test.rb} +3 -2
- data/test/{proxy_test.rb → unit/proxy_test.rb} +2 -1
- data/test/{query_test.rb → unit/query_test.rb} +7 -8
- data/test/unit/rake_task_test.rb +21 -0
- data/test/{request_test.rb → unit/request_test.rb} +8 -2
- data/test/{result_test.rb → unit/result_test.rb} +29 -1
- data/test/{test_mode_test.rb → unit/test_mode_test.rb} +12 -1
- metadata +80 -27
- data/test/custom_block_test.rb +0 -32
- data/test/integration/smoke_test.rb +0 -26
- data/test/near_test.rb +0 -61
- data/test/services_test.rb +0 -393
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4a9925e759e3cd83f49edbe16d9258f047d4706
|
4
|
+
data.tar.gz: 647fe2e7bc4731707a75dde07c8eec629622821a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1515913cc2e937453458d947421278666ffda78d9388480080fb3af5978cd0a7efd89a5272f33fdfb46e9b89899b675d3064b276cf8b8e97091ce6b218d91f7f
|
7
|
+
data.tar.gz: f76ddc572cfb359718ee5da19451462bfeb442a4986560afb6837444756dcfbaf32d3a36025977d08ab68f9e7f9223ef236ec5c354240932c93b90e42dbb1a3b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.8.7
|
3
2
|
- 1.9.2
|
4
3
|
- 1.9.3
|
5
4
|
- 2.0.0
|
5
|
+
- 2.1.0
|
6
6
|
- jruby-19mode
|
7
|
+
- rbx
|
7
8
|
gemfile:
|
8
9
|
- Gemfile
|
9
10
|
- gemfiles/Gemfile.mongoid-2.4.x
|
10
11
|
env: SSL_CERT_DIR=/etc/ssl/certs
|
11
12
|
matrix:
|
12
13
|
exclude:
|
13
|
-
- rvm: 1.8.7
|
14
|
-
gemfile: Gemfile
|
15
|
-
env: SSL_CERT_DIR=/etc/ssl/certs
|
16
14
|
- rvm: 1.9.2
|
17
15
|
gemfile: Gemfile
|
18
16
|
env: SSL_CERT_DIR=/etc/ssl/certs
|
@@ -22,6 +20,12 @@ matrix:
|
|
22
20
|
- rvm: 2.0.0
|
23
21
|
gemfile: gemfiles/Gemfile.mongoid-2.4.x
|
24
22
|
env: SSL_CERT_DIR=/etc/ssl/certs
|
23
|
+
- rvm: 2.1.0
|
24
|
+
gemfile: gemfiles/Gemfile.mongoid-2.4.x
|
25
|
+
env: SSL_CERT_DIR=/etc/ssl/certs
|
25
26
|
- rvm: jruby-19mode
|
26
27
|
gemfile: gemfiles/Gemfile.mongoid-2.4.x
|
27
|
-
env: SSL_CERT_DIR=/etc/ssl/certs
|
28
|
+
env: SSL_CERT_DIR=/etc/ssl/certs
|
29
|
+
- rvm: rbx
|
30
|
+
gemfile: gemfiles/Gemfile.mongoid-2.4.x
|
31
|
+
env: SSL_CERT_DIR=/etc/ssl/certs
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,25 @@ 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.2.0 (2014 Apr 16)
|
7
|
+
-----------
|
8
|
+
|
9
|
+
* DROP SUPPORT for Ruby 1.8.x.
|
10
|
+
* Add :here lookup (thanks github.com/christoph-buente).
|
11
|
+
* Add :cloudmade lookup (thanks github.com/spoptchev).
|
12
|
+
* Add :smarty_streets lookup (thanks github.com/drinks).
|
13
|
+
* Add :maxmind_local IP lookup (thanks github.com/fernandomm).
|
14
|
+
* Add :baidu_ip lookup (thanks github.com/yonggu).
|
15
|
+
* Add :geocodio lookup (thanks github.com/dblock).
|
16
|
+
* Add :lookup option to `Geocoder.search` and `geocoded_by` (thanks github.com/Bonias).
|
17
|
+
* Add support for :maxmind_local on JRuby via jgeoip gem (thanks github.com/gxbe).
|
18
|
+
* Add support for using :maxmind_local with an SQL database, including Rake tasks for downloading CSV data and populating a local DB.
|
19
|
+
* Add support for character encodings based on Content-type header (thanks github.com/timaro).
|
20
|
+
* Add :min_radius option to `near` scope (thanks github.com/phallstrom).
|
21
|
+
* Fix: Yandex city attribute caused exception with certain responses (thanks github.com/dblock).
|
22
|
+
* Change name of MapQuest config option from :licensed to :open and revert default behavior to be MapQuest data (not OpenStreetMaps).
|
23
|
+
* Reduce number of Ruby warnings (thanks github.com/exviva).
|
24
|
+
|
6
25
|
1.1.9 (2013 Dec 11)
|
7
26
|
-------------------
|
8
27
|
|
data/README.md
CHANGED
@@ -7,12 +7,18 @@ Geocoder is a complete geocoding solution for Ruby. With Rails it adds geocoding
|
|
7
7
|
Compatibility
|
8
8
|
-------------
|
9
9
|
|
10
|
-
* Supports multiple Ruby versions: Ruby 1.
|
10
|
+
* Supports multiple Ruby versions: Ruby 1.9.2, 1.9.3, 2.0.0, 2.1.0, JRuby and Rubinius.
|
11
11
|
* Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher).
|
12
12
|
* Supports Rails 3 and 4. If you need to use it with Rails 2 please see the `rails2` branch (no longer maintained, limited feature set).
|
13
13
|
* Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem.
|
14
14
|
|
15
15
|
|
16
|
+
Rails 4.1 Note
|
17
|
+
--------------
|
18
|
+
|
19
|
+
Due to [a change in ActiveRecord's `count` method](https://github.com/rails/rails/pull/10710) you will need to use `count(:all)` to explicitly count all columns ("*") when using a `near` scope. Using `near` and calling `count` with no argument will cause exceptions in many cases.
|
20
|
+
|
21
|
+
|
16
22
|
Installation
|
17
23
|
------------
|
18
24
|
|
@@ -98,9 +104,20 @@ If you have just added geocoding to an existing application with a lot of object
|
|
98
104
|
|
99
105
|
rake geocode:all CLASS=YourModel
|
100
106
|
|
101
|
-
Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `
|
107
|
+
Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example:
|
108
|
+
|
109
|
+
rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100
|
110
|
+
|
111
|
+
### Avoiding Unnecessary API Requests
|
102
112
|
|
103
|
-
|
113
|
+
Geocoding only needs to be performed under certain conditions. To avoid unnecessary work (and quota usage) you will probably want to geocode an object only when:
|
114
|
+
|
115
|
+
* an address is present
|
116
|
+
* the address has been changed since last save (or it has never been saved)
|
117
|
+
|
118
|
+
The exact code will vary depending on the method you use for your geocodable string, but it would be something like this:
|
119
|
+
|
120
|
+
after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? }
|
104
121
|
|
105
122
|
|
106
123
|
Request Geocoding by IP Address
|
@@ -195,6 +212,11 @@ You are not stuck with using the `latitude` and `longitude` database column name
|
|
195
212
|
geocoded_by :address, :latitude => :lat, :longitude => :lon # ActiveRecord
|
196
213
|
geocoded_by :address, :coordinates => :coords # MongoDB
|
197
214
|
|
215
|
+
This means you can geocode multiple addresses as well:
|
216
|
+
|
217
|
+
geocoded_by :start_address, latitude: :start_latitude, longitude: :start_longitude
|
218
|
+
geocoded_by :end_address, latitude: :end_latitude, longitude: :end_longitude
|
219
|
+
|
198
220
|
The `address` method can return any string you'd use to search Google Maps. For example, any of the following are acceptable:
|
199
221
|
|
200
222
|
* "714 Green St, Big Town, MO"
|
@@ -214,6 +236,24 @@ For reverse geocoding you can also specify an alternate name attribute where the
|
|
214
236
|
reverse_geocoded_by :latitude, :longitude, :address => :location # ActiveRecord
|
215
237
|
reverse_geocoded_by :coordinates, :address => :loc # MongoDB
|
216
238
|
|
239
|
+
You can also configure a specific lookup for your model which will override the globally-configured lookup, for example:
|
240
|
+
|
241
|
+
geocoded_by :address, :lookup => :yandex
|
242
|
+
|
243
|
+
You can also specify a proc if you want to choose a lookup based on a specific property of an object, for example you can use specialized lookups for different regions:
|
244
|
+
|
245
|
+
geocoded_by :address, :lookup => lambda{ |obj| obj.geocoder_lookup }
|
246
|
+
|
247
|
+
def geocoder_lookup
|
248
|
+
if country_code == "RU"
|
249
|
+
:yandex
|
250
|
+
elsif country_code == "CN"
|
251
|
+
:baidu
|
252
|
+
else
|
253
|
+
:google
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
217
257
|
|
218
258
|
Advanced Querying
|
219
259
|
-----------------
|
@@ -227,6 +267,11 @@ When querying for objects (if you're using ActiveRecord) you can also look withi
|
|
227
267
|
|
228
268
|
This can also dramatically improve query performance, especially when used in conjunction with indexes on the latitude/longitude columns. Note, however, that returned results do not include `distance` and `bearing` attributes. Note that `#near` performs both bounding box and radius queries for speed.
|
229
269
|
|
270
|
+
You can also specify a minimum radius (if you're using ActiveRecord and not Sqlite) to constrain the
|
271
|
+
lower bound (ie. think of a donut, or ring) by using the `:min_radius` option:
|
272
|
+
|
273
|
+
box = Geocoder::Calculations.bounding_box(center_point, distance, :min_radius => 10.5)
|
274
|
+
|
230
275
|
|
231
276
|
Advanced Geocoding
|
232
277
|
------------------
|
@@ -258,10 +303,10 @@ Every `Geocoder::Result` object, `result`, provides the following data:
|
|
258
303
|
If you're familiar with the results returned by the geocoding service you're using you can access even more data, but you'll need to be familiar with the particular `Geocoder::Result` object you're using and the structure of your geocoding service's responses. (See below for links to geocoding service documentation.)
|
259
304
|
|
260
305
|
|
261
|
-
Geocoding
|
262
|
-
|
306
|
+
Geocoding Service ("Lookup") Configuration
|
307
|
+
------------------------------------------
|
263
308
|
|
264
|
-
|
309
|
+
Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:freegeoip` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services). Some common configuration options are:
|
265
310
|
|
266
311
|
# config/initializers/geocoder.rb
|
267
312
|
Geocoder.configure(
|
@@ -269,6 +314,9 @@ By default Geocoder uses Google's geocoding API to fetch coordinates and street
|
|
269
314
|
# geocoding service (see below for supported options):
|
270
315
|
:lookup => :yandex,
|
271
316
|
|
317
|
+
# IP address geocoding service (see below for supported options):
|
318
|
+
:ip_lookup => :maxmind,
|
319
|
+
|
272
320
|
# to use an API key:
|
273
321
|
:api_key => "...",
|
274
322
|
|
@@ -294,8 +342,33 @@ Please see the [source code for each lookup](https://github.com/alexreisner/geoc
|
|
294
342
|
# with Nominatim:
|
295
343
|
Geocoder.search("Paris", :params => {:countrycodes => "gb,de,fr,es,us"})
|
296
344
|
|
345
|
+
You can also configure multiple geocoding services at once, like this:
|
297
346
|
|
298
|
-
|
347
|
+
Geocoder.configure(
|
348
|
+
|
349
|
+
:timeout => 2,
|
350
|
+
:cache => Redis.new,
|
351
|
+
|
352
|
+
:yandex => {
|
353
|
+
:api_key => "...",
|
354
|
+
:timeout => 5
|
355
|
+
},
|
356
|
+
|
357
|
+
:baidu => {
|
358
|
+
:api_key => "..."
|
359
|
+
},
|
360
|
+
|
361
|
+
:maxmind => {
|
362
|
+
:api_key => "...",
|
363
|
+
:service => :omni
|
364
|
+
}
|
365
|
+
|
366
|
+
)
|
367
|
+
|
368
|
+
The above combines global and service-specific options and could be useful if you specify different geocoding services for different models or under different conditions. Lookup-specific settings override global settings so, for example, in the above the timeout for all lookups would be 2 seconds, except for Yandex which would be 5.
|
369
|
+
|
370
|
+
|
371
|
+
### Street Address Services
|
299
372
|
|
300
373
|
The following is a comparison of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for a service before using it.
|
301
374
|
|
@@ -411,6 +484,17 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
|
|
411
484
|
* **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html
|
412
485
|
* **Limitations**: ?
|
413
486
|
|
487
|
+
#### Here/Nokia (`:here`)
|
488
|
+
|
489
|
+
* **API key**: required
|
490
|
+
* **Quota**: Depending on the API key
|
491
|
+
* **Region**: world
|
492
|
+
* **SSL support**: yes
|
493
|
+
* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard.
|
494
|
+
* **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder
|
495
|
+
* **Terms of Service**: http://developer.here.com/faqs#l&t
|
496
|
+
* **Limitations**: ?
|
497
|
+
|
414
498
|
#### ESRI (`:esri`)
|
415
499
|
|
416
500
|
* **API key**: none
|
@@ -419,7 +503,7 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
|
|
419
503
|
* **SSL support**: yes
|
420
504
|
* **Languages**: English
|
421
505
|
* **Documentation**: http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/
|
422
|
-
* **Terms of Service**: http://www.esri.com/software
|
506
|
+
* **Terms of Service**: http://www.esri.com/legal/software-license
|
423
507
|
* **Limitations**: ?
|
424
508
|
* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`.
|
425
509
|
|
@@ -437,6 +521,53 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
|
|
437
521
|
* **Limitations**: No reverse geocoding.
|
438
522
|
* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(:lookup => :dstk, :host => "localhost:4567")`.
|
439
523
|
|
524
|
+
#### Baidu (`:baidu`)
|
525
|
+
|
526
|
+
* **API key**: required
|
527
|
+
* **Quota**: No quota limits for geocoding
|
528
|
+
* **Region**: China
|
529
|
+
* **SSL support**: no
|
530
|
+
* **Languages**: Chinese (Simplified)
|
531
|
+
* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm
|
532
|
+
* **Terms of Service**: http://developer.baidu.com/map/law.htm
|
533
|
+
* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013
|
534
|
+
* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu, :api_key => "your_api_key")`.
|
535
|
+
|
536
|
+
#### CloudMade (`:cloudmade`)
|
537
|
+
|
538
|
+
* **API key**: required
|
539
|
+
* **Quota**: 100,000 free requests, then purchase 100,000 more for $15
|
540
|
+
* **Region**: world
|
541
|
+
* **SSL support**: yes ($5 per 100,000 requests)
|
542
|
+
* **Languages**: en
|
543
|
+
* **Documentation**: http://cloudmade.com/documentation/geocoding
|
544
|
+
* **Terms of Service**: http://cloudmade.com/api-terms-of-service
|
545
|
+
* **Limitations**: ?
|
546
|
+
|
547
|
+
#### Geocodio (`:geocodio`)
|
548
|
+
|
549
|
+
* **API key**: required
|
550
|
+
* **Quota**: 2,500 free requests/day then purchase $.001 for each
|
551
|
+
* **Region**: US
|
552
|
+
* **SSL support**: no
|
553
|
+
* **Languages**: en
|
554
|
+
* **Documentation**: http://geocod.io/docs
|
555
|
+
* **Terms of Service**: http://geocod.io/terms-of-use
|
556
|
+
* **Limitations**: ?
|
557
|
+
|
558
|
+
#### SmartyStreets (`:smarty_streets`)
|
559
|
+
|
560
|
+
* **API key**: required
|
561
|
+
* **Quota**: 10,000 free, 250/month then purchase at sliding scale. Unlimited free for nonprofits & startups
|
562
|
+
* **Region**: US
|
563
|
+
* **SSL support**: yes
|
564
|
+
* **Languages**: en
|
565
|
+
* **Documentation**: http://smartystreets.com/kb/liveaddress-api/rest-endpoint
|
566
|
+
* **Terms of Service**: http://smartystreets.com/legal/terms-of-service
|
567
|
+
* **Limitations**: No reverse geocoding.
|
568
|
+
|
569
|
+
### IP Address Services
|
570
|
+
|
440
571
|
#### FreeGeoIP (`:freegeoip`)
|
441
572
|
|
442
573
|
* **API key**: none
|
@@ -460,7 +591,40 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
|
|
460
591
|
* **Limitations**: ?
|
461
592
|
* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(:maxmind => {:service => :omni})`.
|
462
593
|
|
463
|
-
####
|
594
|
+
#### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL
|
595
|
+
|
596
|
+
This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter.
|
597
|
+
|
598
|
+
* **API key**: none (requires the GeoLite City database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/legacy/geolite/))
|
599
|
+
* **Quota**: none
|
600
|
+
* **Region**: world
|
601
|
+
* **SSL support**: N/A
|
602
|
+
* **Languages**: English
|
603
|
+
* **Documentation**: http://www.maxmind.com/en/city
|
604
|
+
* **Terms of Service**: ?
|
605
|
+
* **Limitations**: ?
|
606
|
+
* **Notes**: There are two supported formats for MaxMind local data: binary file, and CSV file imported into an SQL database. **You must download a database from MaxMind and set either the `:file` or `:package` configuration option for local lookups to work.**
|
607
|
+
|
608
|
+
**To use a binary file** you must add the *geoip* (or *jgeoip* for JRuby) gem to your Gemfile or have it installed in your system, and specify the path of the MaxMind database in your configuration. For example:
|
609
|
+
|
610
|
+
Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {file: File.join('folder', 'GeoLiteCity.dat')})
|
611
|
+
|
612
|
+
**To use a CSV file** you must import it into an SQL database. The GeoLite *City* and *Country* packages are supported. Configure like so:
|
613
|
+
|
614
|
+
Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {package: :city})
|
615
|
+
|
616
|
+
You can generate ActiveRecord migrations and download and import data via provided rake tasks:
|
617
|
+
|
618
|
+
rails generate geocoder:maxmind:geolite_city
|
619
|
+
|
620
|
+
rake geocoder:maxmind:geolite_city:download
|
621
|
+
rake geocoder:maxmind:geolite_city:extract
|
622
|
+
rake geocoder:maxmind:geolite_city:insert
|
623
|
+
rake geocoder:maxmind:geolite_city:load # runs the above three in sequence
|
624
|
+
|
625
|
+
You can replace `city` with `country` in any of the above tasks, generators, and configurations.
|
626
|
+
|
627
|
+
#### Baidu IP (`:baidu_ip`)
|
464
628
|
|
465
629
|
* **API key**: required
|
466
630
|
* **Quota**: No quota limits for geocoding
|
@@ -470,7 +634,8 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
|
|
470
634
|
* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm
|
471
635
|
* **Terms of Service**: http://developer.baidu.com/map/law.htm
|
472
636
|
* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013
|
473
|
-
* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :
|
637
|
+
* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu_ip, :api_key => "your_api_key")`.
|
638
|
+
|
474
639
|
|
475
640
|
Caching
|
476
641
|
-------
|
data/Rakefile
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Generators
|
5
|
+
module Maxmind
|
6
|
+
class GeoliteCityGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def copy_migration_files
|
12
|
+
migration_template "migration/geolite_city.rb", "db/migrate/geocoder_maxmind_geolite_city.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Define the next_migration_number method (necessary for the
|
16
|
+
# migration_template method to work)
|
17
|
+
def self.next_migration_number(dirname)
|
18
|
+
if ActiveRecord::Base.timestamped_migrations
|
19
|
+
sleep 1 # make sure each time we get a different timestamp
|
20
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
21
|
+
else
|
22
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Generators
|
5
|
+
module Maxmind
|
6
|
+
class GeoliteCountryGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def copy_migration_files
|
12
|
+
migration_template "migration/geolite_country.rb", "db/migrate/geocoder_maxmind_geolite_country.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Define the next_migration_number method (necessary for the
|
16
|
+
# migration_template method to work)
|
17
|
+
def self.next_migration_number(dirname)
|
18
|
+
if ActiveRecord::Base.timestamped_migrations
|
19
|
+
sleep 1 # make sure each time we get a different timestamp
|
20
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
21
|
+
else
|
22
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class GeocoderMaxmindGeoliteCity < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :maxmind_geolite_city_blocks, id: false do |t|
|
4
|
+
t.column :start_ip_num, :bigint, null: false
|
5
|
+
t.column :end_ip_num, :bigint, null: false
|
6
|
+
t.column :loc_id, :bigint, null: false
|
7
|
+
end
|
8
|
+
add_index :maxmind_geolite_city_blocks, :start_ip_num, unique: true
|
9
|
+
|
10
|
+
create_table :maxmind_geolite_city_location, id: false do |t|
|
11
|
+
t.column :loc_id, :bigint, null: false
|
12
|
+
t.string :country, null: false
|
13
|
+
t.string :region, null: false
|
14
|
+
t.string :city
|
15
|
+
t.string :postal_code, null: false
|
16
|
+
t.float :latitude
|
17
|
+
t.float :longitude
|
18
|
+
t.integer :metro_code
|
19
|
+
t.integer :area_code
|
20
|
+
end
|
21
|
+
add_index :maxmind_geolite_city_location, :loc_id, unique: true
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.down
|
25
|
+
drop_table :maxmind_geolite_city
|
26
|
+
end
|
27
|
+
end
|