geocoder 1.1.8 → 1.1.9

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.

Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +13 -1
  4. data/README.md +100 -30
  5. data/Rakefile +1 -1
  6. data/examples/autoexpire_cache_dalli.rb +2 -2
  7. data/examples/cache_bypass.rb +48 -0
  8. data/lib/geocoder/calculations.rb +38 -0
  9. data/lib/geocoder/cli.rb +8 -1
  10. data/lib/geocoder/lookup.rb +3 -0
  11. data/lib/geocoder/lookups/baidu.rb +54 -0
  12. data/lib/geocoder/lookups/base.rb +26 -11
  13. data/lib/geocoder/lookups/dstk.rb +20 -0
  14. data/lib/geocoder/lookups/freegeoip.rb +2 -6
  15. data/lib/geocoder/lookups/geocoder_us.rb +39 -0
  16. data/lib/geocoder/lookups/google.rb +5 -0
  17. data/lib/geocoder/lookups/mapquest.rb +21 -5
  18. data/lib/geocoder/lookups/maxmind.rb +1 -1
  19. data/lib/geocoder/lookups/nominatim.rb +0 -1
  20. data/lib/geocoder/lookups/ovi.rb +14 -4
  21. data/lib/geocoder/query.rb +5 -1
  22. data/lib/geocoder/results/baidu.rb +79 -0
  23. data/lib/geocoder/results/dstk.rb +6 -0
  24. data/lib/geocoder/results/geocoder_us.rb +39 -0
  25. data/lib/geocoder/results/yandex.rb +1 -1
  26. data/lib/geocoder/stores/active_record.rb +12 -6
  27. data/lib/geocoder/stores/mongo_base.rb +5 -2
  28. data/lib/geocoder/version.rb +1 -1
  29. data/lib/tasks/geocoder.rake +2 -0
  30. data/test/cache_test.rb +16 -0
  31. data/test/calculations_test.rb +31 -21
  32. data/test/fixtures/baidu_invalid_key +1 -0
  33. data/test/fixtures/baidu_no_results +1 -0
  34. data/test/fixtures/baidu_reverse +1 -0
  35. data/test/fixtures/baidu_shanghai_pearl_tower +12 -0
  36. data/test/fixtures/geocoder_us_madison_square_garden +1 -0
  37. data/test/fixtures/geocoder_us_no_results +1 -0
  38. data/test/fixtures/google_over_limit +4 -0
  39. data/test/fixtures/mapquest_error +16 -0
  40. data/test/fixtures/mapquest_invalid_api_key +16 -0
  41. data/test/fixtures/mapquest_invalid_request +16 -0
  42. data/test/fixtures/mapquest_no_results +10 -1
  43. data/test/mongoid_test.rb +7 -0
  44. data/test/near_test.rb +18 -0
  45. data/test/proxy_test.rb +13 -0
  46. data/test/query_test.rb +5 -0
  47. data/test/services_test.rb +75 -2
  48. data/test/test_helper.rb +16 -6
  49. metadata +24 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e54ea93888b39c46a8ed298a9d3eca5c6a4533a
4
+ data.tar.gz: 2b72dcae0e8cc61ba37fb831db4ef88b18543b56
5
+ SHA512:
6
+ metadata.gz: b30e519cafc13d8e57c300f6249fdae8736e92503ef3f2bb03b2670eca83f956c3640ddff1f8567bfbb3b80b048ae80a4bebf8f08423a8a137a0d7f3dfa83e2b
7
+ data.tar.gz: dbd472d124b0b795b797abbfe997a9591db207495880c84fbda1f9c2b07626f176be4aab78136e59d347c4492f3b55b41e8381e8e59b85d36945f6d0a18323e1
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
5
6
  - jruby-19mode
6
7
  gemfile:
7
8
  - Gemfile
@@ -18,6 +19,9 @@ matrix:
18
19
  - rvm: 1.9.3
19
20
  gemfile: gemfiles/Gemfile.mongoid-2.4.x
20
21
  env: SSL_CERT_DIR=/etc/ssl/certs
22
+ - rvm: 2.0.0
23
+ gemfile: gemfiles/Gemfile.mongoid-2.4.x
24
+ env: SSL_CERT_DIR=/etc/ssl/certs
21
25
  - rvm: jruby-19mode
22
26
  gemfile: gemfiles/Gemfile.mongoid-2.4.x
23
27
  env: SSL_CERT_DIR=/etc/ssl/certs
data/CHANGELOG.md CHANGED
@@ -1,7 +1,19 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- Per-release changes to Geocoder. Note that only major changes are summarized here. Please see the Git log for all changes.
4
+ Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
5
+
6
+ 1.1.9 (2013 Dec 11)
7
+ -------------------
8
+
9
+ * DEPRECATED support for Ruby 1.8.x. Will be dropped in a future version.
10
+ * Require API key for MapQuest (thanks github.com/robdiciuccio).
11
+ * Add support for geocoder.us and HTTP basic auth (thanks github.com/komba).
12
+ * Add support for Data Science Toolkit lookup (thanks github.com/ejhayes).
13
+ * Add support for Baidu (thanks github.com/mclee).
14
+ * Add Geocoder::Calculations.random_point_near method (thanks github.com/adambray).
15
+ * Fix: #nearbys method with Mongoid (thanks github.com/pascalbetz).
16
+ * Fix: bug in FreeGeoIp lookup that was preventing exception from being raised when configured cache was unavailable.
5
17
 
6
18
  1.1.8 (2013 Apr 22)
7
19
  -------------------
data/README.md CHANGED
@@ -7,9 +7,9 @@ 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.8.7, 1.9.2, 1.9.3, and JRuby.
10
+ * Supports multiple Ruby versions: Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, and JRuby.
11
11
  * Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher).
12
- * Supports Rails 3.x. If you need to use it with Rails 2 please see the `rails2` branch (no longer maintained, limited feature set).
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
 
@@ -98,7 +98,9 @@ If you have just added geocoding to an existing application with a lot of object
98
98
 
99
99
  rake geocode:all CLASS=YourModel
100
100
 
101
- Geocoder will print warnings if you exceed the rate limit for your geocoding service.
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 `sleep` option to the rake task, like so:
102
+
103
+ rake geocode:all CLASS=YourModel sleep=0.25
102
104
 
103
105
 
104
106
  Request Geocoding by IP Address
@@ -121,6 +123,8 @@ To find objects by location, use the following scopes:
121
123
 
122
124
  Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha
123
125
  Venue.near([40.71, 100.23], 20) # venues within 20 miles of a point
126
+ Venue.near([40.71, 100.23], 20, :units => :km)
127
+ # venues within 20 kilometres of a point
124
128
  Venue.geocoded # venues with coordinates
125
129
  Venue.not_geocoded # venues without coordinates
126
130
 
@@ -221,9 +225,7 @@ When querying for objects (if you're using ActiveRecord) you can also look withi
221
225
  box = Geocoder::Calculations.bounding_box(center_point, distance)
222
226
  Venue.within_bounding_box(box)
223
227
 
224
- 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. If you want to improve performance AND have access to distance and bearing info, use both scopes:
225
-
226
- Venue.near(center_point, distance).within_bounding_box(box)
228
+ 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.
227
229
 
228
230
 
229
231
  Advanced Geocoding
@@ -300,7 +302,7 @@ The following is a comparison of the supported geocoding APIs. The "Limitations"
300
302
  #### Google (`:google`, `:google_premier`)
301
303
 
302
304
  * **API key**: required for Premier (do NOT use a key for the free version)
303
- * **Key signup**: http://code.google.com/apis/maps/signup.html
305
+ * **Key signup**: https://developers.google.com/maps/documentation/business/
304
306
  * **Quota**: 2,500 requests/day, 100,000 with Google Maps API Premier
305
307
  * **Region**: world
306
308
  * **SSL support**: yes
@@ -346,7 +348,7 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
346
348
  * **Languages**: ?
347
349
  * **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim
348
350
  * **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
349
- * **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers. Data licensed under CC-BY-SA (you must provide attribution).
351
+ * **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). Data licensed under CC-BY-SA (you must provide attribution).
350
352
 
351
353
  #### Yandex (`:yandex`)
352
354
 
@@ -370,9 +372,22 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
370
372
  * **Terms of Service**: http://geocoder.ca/?terms=1
371
373
  * **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission."
372
374
 
375
+ #### Geocoder.us (`:geocoder_us`)
376
+
377
+ * **API key**: HTTP Basic Auth
378
+ * **Sign up**: http://geocoder.us/user/signup
379
+ * **Quota**: You can purchase 20,000 credits at a time for $50
380
+ * **Region**: US
381
+ * **SSL support**: no
382
+ * **Languages**: English
383
+ * **Documentation**: http://geocoder.us/help/
384
+ * **Terms of Service**: http://geocoder.us/terms.shtml
385
+ * **Limitations**: ?
386
+
373
387
  #### Mapquest (`:mapquest`)
374
388
 
375
- * **API key**: required for the licensed API, do not use for open tier
389
+ * **API key**: required
390
+ * **Key signup**: http://developer.mapquest.com/web/products/open
376
391
  * **Quota**: ?
377
392
  * **HTTP Headers**: in order to use the licensed API you can configure the http_headers to include a referer as so:
378
393
  `Geocoder.configure(:http_headers => { "Referer" => "http://foo.com" })`
@@ -383,6 +398,7 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
383
398
  * **Documentation**: http://www.mapquestapi.com/geocoding/
384
399
  * **Terms of Service**: http://info.mapquest.com/terms-of-use/
385
400
  * **Limitations**: ?
401
+ * **Notes**: You can specify the licensed API by setting: `Geocoder.configure(:mapquest => {:licensed => true})` (defaults to free "open" version)
386
402
 
387
403
  #### Ovi/Nokia (`:ovi`)
388
404
 
@@ -395,14 +411,40 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
395
411
  * **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html
396
412
  * **Limitations**: ?
397
413
 
414
+ #### ESRI (`:esri`)
415
+
416
+ * **API key**: none
417
+ * **Quota**: Required for some scenarios (see Terms of Service)
418
+ * **Region**: world
419
+ * **SSL support**: yes
420
+ * **Languages**: English
421
+ * **Documentation**: http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/
422
+ * **Terms of Service**: http://www.esri.com/software/arcgis/arcgisonline/services/geoservices
423
+ * **Limitations**: ?
424
+ * **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`.
425
+
426
+ #### Data Science Toolkit (`:dstk`)
427
+
428
+ Data Science Toolkit provides an API whose reponse format is like Google's but which can be set up as a privately hosted service.
429
+
430
+ * **API key**: none
431
+ * **Quota**: None quota if you are self-hosting the service.
432
+ * **Region**: world
433
+ * **SSL support**: ?
434
+ * **Languages**: en
435
+ * **Documentation**: http://www.datasciencetoolkit.org/developerdocs
436
+ * **Terms of Service**: http://www.datasciencetoolkit.org/developerdocs#googlestylegeocoder
437
+ * **Limitations**: No reverse geocoding.
438
+ * **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
+
398
440
  #### FreeGeoIP (`:freegeoip`)
399
441
 
400
442
  * **API key**: none
401
- * **Quota**: 1000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over.
443
+ * **Quota**: 10000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over.
402
444
  * **Region**: world
403
445
  * **SSL support**: no
404
446
  * **Languages**: English
405
- * **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.rst
447
+ * **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md
406
448
  * **Terms of Service**: ?
407
449
  * **Limitations**: ?
408
450
 
@@ -418,18 +460,17 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
418
460
  * **Limitations**: ?
419
461
  * **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(:maxmind => {:service => :omni})`.
420
462
 
421
- #### ESRI (`:esri`)
422
-
423
- * **API key**: none
424
- * **Quota**: Required for some scenarios (see Terms of Service)
425
- * **Region**: world
426
- * **SSL support**: yes
427
- * **Languages**: English
428
- * **Documentation**: http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/
429
- * **Terms of Service**: http://www.esri.com/software/arcgis/arcgisonline/services/geoservices
430
- * **Limitations**: ?
431
- * **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`.
463
+ #### Baidu (`:baidu`)
432
464
 
465
+ * **API key**: required
466
+ * **Quota**: No quota limits for geocoding
467
+ * **Region**: China
468
+ * **SSL support**: no
469
+ * **Languages**: Chinese (Simplified)
470
+ * **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm
471
+ * **Terms of Service**: http://developer.baidu.com/map/law.htm
472
+ * **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 => :baidu, :api_key => "your_api_key")`.
433
474
 
434
475
  Caching
435
476
  -------
@@ -440,10 +481,9 @@ It's a good idea, when relying on any external service, to cache retrieved data.
440
481
 
441
482
  This example uses Redis, but the cache store can be any object that supports these methods:
442
483
 
443
- * `store#[](key)` - retrieves a value
444
- * `store#[]=(key, value)` - stores a value
445
- * `store#keys` - lists all keys
446
- * `store#del(url)` - deletes a value
484
+ * `store#[](key)` or `#get` or `#read` - retrieves a value
485
+ * `store#[]=(key, value)` or `#set` or `#write` - stores a value
486
+ * `store#del(url)` - deletes a value
447
487
 
448
488
  Even a plain Ruby hash will work, though it's not a great choice (cleared out when app is restarted, not shared between app instances, etc).
449
489
 
@@ -520,7 +560,7 @@ For example:
520
560
  after_validation :reverse_geocode, :if => :has_coordinates
521
561
  after_validation :geocode, :if => :has_location, :unless => :has_coordinates
522
562
 
523
- end
563
+ end
524
564
 
525
565
  Use Outside of Rails
526
566
  --------------------
@@ -590,6 +630,13 @@ When you install the Geocoder gem it adds a `geocode` command to your shell. You
590
630
 
591
631
  There are also a number of options for setting the geocoding API, key, and language, viewing the raw JSON reponse, and more. Please run `geocode -h` for details.
592
632
 
633
+ Numeric Data Types and Precision
634
+ --------------------------------
635
+
636
+ Geocoder works with any numeric data type (e.g. float, double, decimal) on which trig (and other mathematical) functions can be performed.
637
+
638
+ A summary of the relationship between geographic precision and the number of decimal places in latitude and longitude degree values is available on [Wikipedia](http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy). As an example: at the equator, latitude/longitude values with 4 decimal places give about 11 metres precision, whereas 5 decimal places gives roughly 1 metre precision.
639
+
593
640
  Notes on MongoDB
594
641
  ----------------
595
642
 
@@ -616,7 +663,7 @@ Notes on Non-Rails Frameworks
616
663
 
617
664
  If you are using Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino) you will need to add this in your model before calling Geocoder methods:
618
665
 
619
- extend Geocoder::Model::ActiveRecord
666
+ extend Geocoder::Model::ActiveRecord
620
667
 
621
668
  Optimisation of Distance Queries
622
669
  --------------------------------
@@ -715,12 +762,35 @@ When reporting an issue, please list the version of Geocoder you are using and a
715
762
  Known Issue
716
763
  -----------
717
764
 
718
- You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa). Instead, try using `joins` and pass a `:select` option to the `near` scope to get the columns you want. For example:
765
+ You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa).
766
+
767
+ Instead of using `includes` to reduce the number of database queries, try using `joins` with either the `:select` option or a call to `preload`. For example:
719
768
 
720
- # instead of City.near(...).includes(:venues)
769
+ # Pass a :select option to the near scope to get the columns you want.
770
+ # Instead of City.near(...).includes(:venues), try:
721
771
  City.near("Omaha, NE", 20, :select => "cities.*, venues.*").joins(:venues)
722
772
 
773
+ # This preload call will normally trigger two queries regardless of the
774
+ # number of results; one query on hotels, and one query on administrators.
775
+ # Instead of Hotel.near(...).includes(:administrator), try:
776
+ Hotel.near("London, UK", 50).joins(:administrator).preload(:administrator)
777
+
723
778
  If anyone has a more elegant solution to this problem I am very interested in seeing it.
724
779
 
725
780
 
781
+ Contributing
782
+ ------------
783
+
784
+ Contributions are welcome via pull requests on Github. Please respect the following guidelines:
785
+
786
+ * Each pull request should implement ONE feature or bugfix. If you want to add or fix more than one thing, submit more than one pull request.
787
+ * Do not commit changes to files that are irrelevant to your feature or bugfix (eg: `.gitignore`).
788
+ * Do not add dependencies on other gems.
789
+ * Do not add unnecessary `require` statements which could cause LoadErrors on certain systems.
790
+ * Remember: Geocoder needs to run outside of Rails. Don't assume things like ActiveSupport are available.
791
+ * Do not add to base configuration options; instead document required lookup-specific options in the README.
792
+ * Be willing to accept criticism and work on improving your code; Geocoder is used by thousands of developers and care must be taken not to introduce bugs.
793
+ * Be aware that the pull request review process is not immediate, and is generally proportional to the size of the pull request.
794
+
795
+
726
796
  Copyright (c) 2009-12 Alex Reisner, released under the MIT license
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ Rake::TestTask.new(:integration) do |test|
14
14
  test.verbose = true
15
15
  end
16
16
 
17
- task :default => [:test, :integration]
17
+ task :default => [:test]
18
18
 
19
19
  require 'rdoc/task'
20
20
  Rake::RDocTask.new do |rdoc|
@@ -20,7 +20,7 @@ class AutoexpireCacheDalli
20
20
  if value.nil?
21
21
  del(url)
22
22
  else
23
- key_cache_add(url) if @store.add(key, YAML::dump(value), @ttl)
23
+ key_cache_add(url) if @store.add(url, YAML::dump(value), @ttl)
24
24
  end
25
25
  value
26
26
  end
@@ -30,7 +30,7 @@ class AutoexpireCacheDalli
30
30
  end
31
31
 
32
32
  def del(url)
33
- key_cache_delete(url) if @store.delete(key)
33
+ key_cache_delete(url) if @store.delete(url)
34
34
  end
35
35
 
36
36
  private
@@ -0,0 +1,48 @@
1
+ # This class allows you to configure how Geocoder should treat errors that occur when
2
+ # the cache is not available.
3
+ # Configure it like this
4
+ # config/initializers/geocoder.rb
5
+ # Geocoder.configure(
6
+ # :cache => Geocoder::CacheBypass.new(Redis.new)
7
+ # )
8
+ #
9
+ # Depending on the value of @bypass this will either
10
+ # raise the exception (true) or swallow it and pretend the cache did not return a hit (false)
11
+ #
12
+ class Geocoder::CacheBypass
13
+ def initialize(target, bypass = true)
14
+ @target = target
15
+ @bypass = bypass
16
+ end
17
+
18
+
19
+ def [](key)
20
+ with_bypass { @target[key] }
21
+ end
22
+
23
+ def []=(key, value)
24
+ with_bypass(value) { @target[key] = value }
25
+ end
26
+
27
+ def keys
28
+ with_bypass([]) { @target.keys }
29
+ end
30
+
31
+ def del(key)
32
+ with_bypass { @target.del(key) }
33
+ end
34
+
35
+ private
36
+
37
+ def with_bypass(return_value_if_exception = nil, &block)
38
+ begin
39
+ yield
40
+ rescue
41
+ if @bypass
42
+ return_value_if_exception
43
+ else
44
+ raise # reraise original exception
45
+ end
46
+ end
47
+ end
48
+ end
@@ -216,6 +216,44 @@ module Geocoder
216
216
  ]
217
217
  end
218
218
 
219
+ ##
220
+ # Random point within a circle of provided radius centered
221
+ # around the provided point
222
+ # Takes one point, one radius, and an options hash.
223
+ # The points are given in the same way that points are given to all
224
+ # Geocoder methods that accept points as arguments. They can be:
225
+ #
226
+ # * an array of coordinates ([lat,lon])
227
+ # * a geocodable address (string)
228
+ # * a geocoded object (one which implements a +to_coordinates+ method
229
+ # which returns a [lat,lon] array
230
+ #
231
+ # The options hash supports:
232
+ #
233
+ # * <tt>:units</tt> - <tt>:mi</tt> or <tt>:km</tt>
234
+ # Use Geocoder.configure(:units => ...) to configure default units.
235
+ def random_point_near(center, radius, options = {})
236
+
237
+ # set default options
238
+ options[:units] ||= Geocoder.config.units
239
+
240
+ # convert to coordinate arrays
241
+ center = extract_coordinates(center)
242
+
243
+ earth_circumference = 2 * Math::PI * earth_radius(options[:units])
244
+ max_degree_delta = 360.0 * (radius / earth_circumference)
245
+
246
+ # random bearing in radians
247
+ theta = 2 * Math::PI * rand
248
+
249
+ # random radius, use the square root to ensure a uniform
250
+ # distribution of points over the circle
251
+ r = Math.sqrt(rand) * max_degree_delta
252
+
253
+ delta_lat, delta_long = [r * Math.cos(theta), r * Math.sin(theta)]
254
+ [center[0] + delta_lat, center[1] + delta_long]
255
+ end
256
+
219
257
  ##
220
258
  # Convert degrees to radians.
221
259
  # If an array (or multiple arguments) is passed,
data/lib/geocoder/cli.rb CHANGED
@@ -8,6 +8,11 @@ module Geocoder
8
8
  show_url = false
9
9
  show_json = false
10
10
 
11
+ # remove arguments that are probably coordinates so they are not
12
+ # processed as arguments (eg: -31.96047031,115.84274631)
13
+ coords = args.select{ |i| i.match(/^-\d/) }
14
+ args -= coords
15
+
11
16
  OptionParser.new{ |opts|
12
17
  opts.banner = "Usage:\n geocode [options] <location>"
13
18
  opts.separator "\nOptions: "
@@ -65,7 +70,9 @@ module Geocoder
65
70
  end
66
71
  }.parse!(args)
67
72
 
68
- query = args.join(" ")
73
+ # concatenate args with coords that might have been removed
74
+ # before option processing
75
+ query = (args + coords).join(" ")
69
76
 
70
77
  if query == ""
71
78
  out << "Please specify a location (run `geocode -h` for more info).\n"
@@ -21,16 +21,19 @@ module Geocoder
21
21
  #
22
22
  def street_services
23
23
  [
24
+ :dstk,
24
25
  :esri,
25
26
  :google,
26
27
  :google_premier,
27
28
  :yahoo,
28
29
  :bing,
29
30
  :geocoder_ca,
31
+ :geocoder_us,
30
32
  :yandex,
31
33
  :nominatim,
32
34
  :mapquest,
33
35
  :ovi,
36
+ :baidu,
34
37
  :test
35
38
  ]
36
39
  end