geokit 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/README.markdown +6 -0
- data/geokit.gemspec +2 -2
- data/lib/geokit.rb +1 -1
- data/lib/geokit/geocoders.rb +19 -4
- data/lib/geokit/mappable.rb +11 -0
- data/test/test_google_geocoder.rb +18 -0
- data/test/test_latlng.rb +17 -1
- data/test/test_yahoo_geocoder.rb +18 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 1.3.0 / 2009-04-11
|
2
|
+
* Added capability to define multiple API keys for different domains that may be pointing to the same application (thanks Glenn Powell)
|
3
|
+
* Added numeric accuracy accessor for Yahoo and Google geocoders (thanks Andrew Fecheyr Lippens)
|
4
|
+
* Implement #hash and #eql? on LatLng to allow for using it as a hash key (thanks Luke Melia and Ross Kaffenberger)
|
5
|
+
*
|
6
|
+
|
1
7
|
=== 1.2.6 / 2009-03-19
|
2
8
|
* misc minor fixes
|
3
9
|
|
data/README.markdown
CHANGED
@@ -74,6 +74,12 @@ If you're using this gem by itself, here are the configuration options:
|
|
74
74
|
# See http://www.google.com/apis/maps/signup.html
|
75
75
|
# and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
|
76
76
|
Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'
|
77
|
+
|
78
|
+
# You can also set multiple API KEYS for different domains that may be directed to this same application.
|
79
|
+
# The domain from which the current user is being directed will automatically be updated for Geokit via
|
80
|
+
# the GeocoderControl class, which gets it's begin filter mixed into the ActionController.
|
81
|
+
# You define these keys with a Hash as follows:
|
82
|
+
#Geokit::Geocoders::google = { 'rubyonrails.org' => 'RUBY_ON_RAILS_API_KEY', 'ruby-docs.org' => 'RUBY_DOCS_API_KEY' }
|
77
83
|
|
78
84
|
# This is your username and password for geocoder.us.
|
79
85
|
# To use the free service, the value can be set to nil or false. For
|
data/geokit.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{geokit}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Andre Lewis and Bill Eisenhauer"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-4-11}
|
10
10
|
s.description = %q{Geokit Gem}
|
11
11
|
s.email = ["andre@earthcode.com / bill_eisenhauer@yahoo.com"]
|
12
12
|
s.extra_rdoc_files = ["Manifest.txt", "README.markdown"]
|
data/lib/geokit.rb
CHANGED
data/lib/geokit/geocoders.rb
CHANGED
@@ -72,16 +72,29 @@ module Geokit
|
|
72
72
|
@@provider_order = [:google,:us]
|
73
73
|
@@logger=Logger.new(STDOUT)
|
74
74
|
@@logger.level=Logger::INFO
|
75
|
+
@@domain = nil
|
76
|
+
|
77
|
+
def self.domain
|
78
|
+
@@domain
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.domain=(obj)
|
82
|
+
@@domain = obj
|
83
|
+
end
|
75
84
|
|
76
85
|
[:yahoo, :google, :geocoder_us, :geocoder_ca, :geonames, :provider_order, :timeout,
|
77
|
-
:proxy_addr, :proxy_port, :proxy_user, :proxy_pass
|
86
|
+
:proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :logger].each do |sym|
|
78
87
|
class_eval <<-EOS, __FILE__, __LINE__
|
79
88
|
def self.#{sym}
|
80
|
-
if defined?(#{sym.to_s.upcase})
|
89
|
+
value = if defined?(#{sym.to_s.upcase})
|
81
90
|
#{sym.to_s.upcase}
|
82
91
|
else
|
83
92
|
@@#{sym}
|
84
93
|
end
|
94
|
+
if value.is_a?(Hash)
|
95
|
+
value = (self.domain.nil? ? nil : value[self.domain]) || value.values.first
|
96
|
+
end
|
97
|
+
value
|
85
98
|
end
|
86
99
|
|
87
100
|
def self.#{sym}=(obj)
|
@@ -298,6 +311,8 @@ module Geokit
|
|
298
311
|
res.zip=doc.elements['//Zip'].text if doc.elements['//Zip'] && doc.elements['//Zip'].text != nil
|
299
312
|
res.street_address=doc.elements['//Address'].text if doc.elements['//Address'] && doc.elements['//Address'].text != nil
|
300
313
|
res.precision=doc.elements['//Result'].attributes['precision'] if doc.elements['//Result']
|
314
|
+
# set the accuracy as google does (added by Andruby)
|
315
|
+
res.accuracy=%w{unknown country state state city zip zip+4 street address building}.index(res.precision)
|
301
316
|
res.success=true
|
302
317
|
return res
|
303
318
|
else
|
@@ -441,8 +456,8 @@ module Geokit
|
|
441
456
|
# Translate accuracy into Yahoo-style token address, street, zip, zip+4, city, state, country
|
442
457
|
# For Google, 1=low accuracy, 8=high accuracy
|
443
458
|
address_details=doc.elements['.//*[local-name() = "AddressDetails"]']
|
444
|
-
accuracy = address_details ? address_details.attributes['Accuracy'].to_i : 0
|
445
|
-
res.precision=%w{unknown country state state city zip zip+4 street address building}[accuracy]
|
459
|
+
res.accuracy = address_details ? address_details.attributes['Accuracy'].to_i : 0
|
460
|
+
res.precision=%w{unknown country state state city zip zip+4 street address building}[res.accuracy]
|
446
461
|
res.success=true
|
447
462
|
|
448
463
|
return res
|
data/lib/geokit/mappable.rb
CHANGED
@@ -251,6 +251,14 @@ module Geokit
|
|
251
251
|
other.is_a?(LatLng) ? self.lat == other.lat && self.lng == other.lng : false
|
252
252
|
end
|
253
253
|
|
254
|
+
def hash
|
255
|
+
lat.hash + lng.hash
|
256
|
+
end
|
257
|
+
|
258
|
+
def eql?(other)
|
259
|
+
self == other
|
260
|
+
end
|
261
|
+
|
254
262
|
# A *class* method to take anything which can be inferred as a point and generate
|
255
263
|
# a LatLng from it. You should use this anything you're not sure what the input is,
|
256
264
|
# and want to deal with it as a LatLng if at all possible. Can take:
|
@@ -317,6 +325,9 @@ module Geokit
|
|
317
325
|
attr_accessor :success, :provider, :precision
|
318
326
|
# Street number and street name are extracted from the street address attribute.
|
319
327
|
attr_reader :street_number, :street_name
|
328
|
+
# accuracy is set for Yahoo and Google geocoders, it is a numeric value of the
|
329
|
+
# precision. see http://code.google.com/apis/maps/documentation/geocoding/#GeocodingAccuracy
|
330
|
+
attr_accessor :accuracy
|
320
331
|
|
321
332
|
# Constructor expects a hash of symbols to correspond with attributes.
|
322
333
|
def initialize(h={})
|
@@ -50,6 +50,15 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
50
50
|
assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
|
51
51
|
assert_equal "google", res.provider
|
52
52
|
end
|
53
|
+
|
54
|
+
def test_google_full_address_accuracy
|
55
|
+
response = MockSuccess.new
|
56
|
+
response.expects(:body).returns(GOOGLE_FULL)
|
57
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
|
58
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
59
|
+
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
60
|
+
assert_equal 8, res.accuracy
|
61
|
+
end
|
53
62
|
|
54
63
|
def test_google_city
|
55
64
|
response = MockSuccess.new
|
@@ -66,6 +75,15 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
66
75
|
assert_equal "google", res.provider
|
67
76
|
end
|
68
77
|
|
78
|
+
def test_google_city_accuracy
|
79
|
+
response = MockSuccess.new
|
80
|
+
response.expects(:body).returns(GOOGLE_CITY)
|
81
|
+
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
|
82
|
+
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
83
|
+
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
84
|
+
assert_equal 4, res.accuracy
|
85
|
+
end
|
86
|
+
|
69
87
|
def test_google_city_with_geo_loc
|
70
88
|
response = MockSuccess.new
|
71
89
|
response.expects(:body).returns(GOOGLE_CITY)
|
data/test/test_latlng.rb
CHANGED
@@ -128,5 +128,21 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
128
128
|
res=Geokit::LatLng.normalize([lat,lng])
|
129
129
|
assert_equal res,Geokit::LatLng.new(lat,lng)
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
|
+
def test_hash
|
133
|
+
lat=37.7690
|
134
|
+
lng=-122.443
|
135
|
+
first = Geokit::LatLng.new(lat,lng)
|
136
|
+
second = Geokit::LatLng.new(lat,lng)
|
137
|
+
assert_equal first.hash, second.hash
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_eql?
|
141
|
+
lat=37.7690
|
142
|
+
lng=-122.443
|
143
|
+
first = Geokit::LatLng.new(lat,lng)
|
144
|
+
second = Geokit::LatLng.new(lat,lng)
|
145
|
+
assert first.eql?(second)
|
146
|
+
assert second.eql?(first)
|
147
|
+
end
|
132
148
|
end
|
data/test/test_yahoo_geocoder.rb
CHANGED
@@ -32,6 +32,15 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
32
32
|
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
|
33
33
|
end
|
34
34
|
|
35
|
+
def test_yahoo_full_address_accuracy
|
36
|
+
response = MockSuccess.new
|
37
|
+
response.expects(:body).returns(YAHOO_FULL)
|
38
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
|
39
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
40
|
+
res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
|
41
|
+
assert_equal 8, res.accuracy
|
42
|
+
end
|
43
|
+
|
35
44
|
def test_yahoo_full_address_with_geo_loc
|
36
45
|
response = MockSuccess.new
|
37
46
|
response.expects(:body).returns(YAHOO_FULL)
|
@@ -48,6 +57,15 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
48
57
|
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
|
49
58
|
end
|
50
59
|
|
60
|
+
def test_yahoo_city_accuracy
|
61
|
+
response = MockSuccess.new
|
62
|
+
response.expects(:body).returns(YAHOO_CITY)
|
63
|
+
url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
|
64
|
+
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
65
|
+
res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
|
66
|
+
assert_equal 4, res.accuracy
|
67
|
+
end
|
68
|
+
|
51
69
|
def test_yahoo_city_with_geo_loc
|
52
70
|
response = MockSuccess.new
|
53
71
|
response.expects(:body).returns(YAHOO_CITY)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geokit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andre Lewis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|