geocoder 1.4.1 → 1.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3067b487565dbc6f761d20315246d3524e350a4
4
- data.tar.gz: a2e89172c147db3050c203e6507da323e54d8a58
3
+ metadata.gz: 71a3f14779563a0e64bcd6929d538dbbc46b41c3
4
+ data.tar.gz: 4a9b31b197ed4970caa46593b64afa68be37dc1d
5
5
  SHA512:
6
- metadata.gz: 811f3224d6926014a1c910b605fd6644078c4808893552b8cedd31987650616323e54ba74564f20cbafbe61b39eb1b347e80912d69ab5c2f84153b4281800408
7
- data.tar.gz: bc6301d8b24595749190b0d527ffcd8aecc1f8a804b1fc9cacc68bc7c61b92ea8f544940f09306a428653d65a28bc76536a7545cc76a5d3fd144e3a4c12aa86c
6
+ metadata.gz: f9160c54cdb4327cc02cb195865e0018c50a3f90879eff9f0db898f7f8d445e6d421d941c7e99ca9c3d51484cf726c8ec0c7ddeb0f23d1629d90a91548167457
7
+ data.tar.gz: c7b57fbb01fbe1f9a417dfb42c99dd151127824279e7dd56604b3eced51e24c6a5f795f312ed7ae90a81b3157e5ba0bf599692255702bc670dd28ecbf45f0d63
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@ 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.4.2 (2017 Jan 31)
7
+ -------------------
8
+ * Fix bug that caused Model.near to return an incorrect query in some cases.
9
+
6
10
  1.4.1 (2016 Dec 2)
7
11
  -------------------
8
12
  * Add :location_iq lookup (thanks github.com/aleemuddin13 and glsignal).
data/README.md CHANGED
@@ -15,8 +15,8 @@ Compatibility
15
15
  * Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem.
16
16
 
17
17
 
18
- Rails 4.1 Note
19
- --------------
18
+ Note on Rails 4.1 and Greater
19
+ -----------------------------
20
20
 
21
21
  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.
22
22
 
@@ -402,7 +402,7 @@ The following is a comparison of the supported geocoding APIs. The "Limitations"
402
402
  #### Google (`:google`)
403
403
 
404
404
  * **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `:use_https => true` in `Geocoder.configure`)
405
- * **Key signup**: https://console.developers.google.com//flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE
405
+ * **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE
406
406
  * **Quota**: 2,500 requests/24 hrs, 5 requests/second
407
407
  * **Region**: world
408
408
  * **SSL support**: yes (required if key is used)
@@ -516,7 +516,7 @@ The [Google Places Details API](https://developers.google.com/places/documentati
516
516
  #### Mapbox (`:mapbox`)
517
517
 
518
518
  * **API key**: required
519
- * **Dataset**: Uses `mapbox.places` dataset by default. Specific the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(:mapbox => {:dataset => "mapbox.places-permanent"})`
519
+ * **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(:mapbox => {:dataset => "mapbox.places-permanent"})`
520
520
  * **Key signup**: https://www.mapbox.com/pricing/
521
521
  * **Quota**: depends on plan
522
522
  * **Region**: complete coverage of US and Canada, partial coverage elsewhere (see for details: https://www.mapbox.com/developers/api/geocoding/#coverage)
@@ -42,7 +42,12 @@ module Geocoder
42
42
  # Returns true if all given arguments are valid latitude/longitude values.
43
43
  #
44
44
  def coordinates_present?(*args)
45
- args.all? { |a| a.is_a? Numeric and !a.to_f.nan? }
45
+ args.each do |a|
46
+ # note that Float::NAN != Float::NAN
47
+ # still, this could probably be improved:
48
+ return false if (!a.is_a?(Numeric) or a.to_s == "NaN")
49
+ end
50
+ true
46
51
  end
47
52
 
48
53
  ##
@@ -392,8 +397,13 @@ module Geocoder
392
397
  def extract_coordinates(point)
393
398
  case point
394
399
  when Array
395
- if point.size == 2 and coordinates_present?(*point)
396
- return point.map {|coords| coords.to_f}
400
+ if point.size == 2
401
+ lat, lon = point
402
+ if !lat.nil? && lat.respond_to?(:to_f) and
403
+ !lon.nil? && lon.respond_to?(:to_f)
404
+ then
405
+ return [ lat.to_f, lon.to_f ]
406
+ end
397
407
  end
398
408
  when String
399
409
  point = Geocoder.coordinates(point) and return point
@@ -15,7 +15,7 @@ module Geocoder::Lookup
15
15
  if zipcode_only?(query)
16
16
  "#{protocol}://us-zipcode.api.smartystreets.com/lookup?#{url_query_string(query)}"
17
17
  else
18
- "#{protocol}://api.smartystreets.com/street-address?#{url_query_string(query)}"
18
+ "#{protocol}://us-street.api.smartystreets.com/street-address?#{url_query_string(query)}"
19
19
  end
20
20
  end
21
21
 
@@ -4,9 +4,7 @@ module Geocoder::Result
4
4
  class Nominatim < Base
5
5
 
6
6
  def poi
7
- %w[building university school hospital mall hotel restaurant stadium bus_stop tram_stop].each do |key|
8
- return @data['address'][key] if @data['address'].key?(key)
9
- end
7
+ return @data['address'][place_type] if @data['address'].key?(place_type)
10
8
  return nil
11
9
  end
12
10
 
@@ -25,11 +25,19 @@ module Geocoder::Result
25
25
  end
26
26
 
27
27
  def country
28
- address_details['CountryName']
28
+ if address_details
29
+ address_details['CountryName']
30
+ else
31
+ ""
32
+ end
29
33
  end
30
34
 
31
35
  def country_code
32
- address_details['CountryNameCode']
36
+ if address_details
37
+ address_details['CountryNameCode']
38
+ else
39
+ ""
40
+ end
33
41
  end
34
42
 
35
43
  def state
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require "geocoder/models/mongoid"
2
+
1
3
  namespace :geocode do
2
4
  desc "Geocode all objects without coordinates."
3
5
  task :all => :environment do
@@ -8,22 +10,28 @@ namespace :geocode do
8
10
  raise "Please specify a CLASS (model)" unless class_name
9
11
  klass = class_from_string(class_name)
10
12
  batch = (batch.to_i unless batch.nil?) || 1000
13
+ orm = (klass < Geocoder::Model::Mongoid) ? 'mongoid' : 'active_record'
11
14
  reverse = false unless reverse.to_s.downcase == 'true'
12
15
 
13
- if reverse
14
- klass.not_reverse_geocoded.find_each(batch_size: batch) do |obj|
15
- obj.reverse_geocode; obj.save
16
- sleep(sleep_timer.to_f) unless sleep_timer.nil?
16
+ geocode_record = lambda { |obj|
17
+ reverse ? obj.reverse_geocode : obj.geocode
18
+ obj.save
19
+ sleep(sleep_timer.to_f) unless sleep_timer.nil?
20
+ }
21
+
22
+ scope = reverse ? klass.not_reverse_geocoded : klass.not_geocoded
23
+ if orm == 'mongoid'
24
+ scope.each do |obj|
25
+ geocode_record.call(obj)
17
26
  end
18
- else
19
- klass.not_geocoded.find_each(batch_size: batch) do |obj|
20
- obj.geocode; obj.save
21
- sleep(sleep_timer.to_f) unless sleep_timer.nil?
27
+ elsif orm == 'active_record'
28
+ scope.find_each(batch_size: batch) do |obj|
29
+ geocode_record.call(obj)
22
30
  end
23
31
  end
32
+
24
33
  end
25
34
  end
26
-
27
35
  ##
28
36
  # Get a class object from the string given in the shell environment.
29
37
  # Similar to ActiveSupport's +constantize+ method.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides object geocoding (by street or IP address), reverse geocoding
14
14
  (coordinates to street address), distance queries for ActiveRecord and Mongoid,
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  requirements: []
164
164
  rubyforge_project:
165
- rubygems_version: 2.5.1
165
+ rubygems_version: 2.6.8
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: Complete geocoding solution for Ruby.