geokit 1.6.0 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +7 -21
- data/lib/geokit.rb +1 -2
- data/lib/geokit/geocoders.rb +219 -194
- data/lib/geokit/mappable.rb +98 -89
- data/test/test_base_geocoder.rb +11 -11
- data/test/test_bounds.rb +22 -22
- data/test/test_ca_geocoder.rb +17 -17
- data/test/test_geoloc.rb +15 -15
- data/test/test_geoplugin_geocoder.rb +5 -5
- data/test/test_google_geocoder.rb +30 -30
- data/test/test_google_geocoder3.rb +107 -86
- data/test/test_google_reverse_geocoder.rb +16 -16
- data/test/test_inflector.rb +3 -3
- data/test/test_ipgeocoder.rb +13 -13
- data/test/test_latlng.rb +48 -36
- data/test/test_multi_geocoder.rb +17 -17
- data/test/test_multi_ip_geocoder.rb +5 -5
- data/test/test_us_geocoder.rb +17 -17
- data/test/test_yahoo_geocoder.rb +27 -31
- metadata +29 -38
- data/History.txt +0 -77
- data/Manifest.txt +0 -21
- data/geokit.gemspec +0 -38
data/test/test_base_geocoder.rb
CHANGED
@@ -20,32 +20,32 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
|
20
20
|
class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
|
21
21
|
def self.do_get(url)
|
22
22
|
sleep(2)
|
23
|
-
end
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
26
|
# Defines common test fixtures.
|
27
27
|
def setup
|
28
|
-
@address = 'San Francisco, CA'
|
29
|
-
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
|
30
|
-
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
|
31
|
-
|
28
|
+
@address = 'San Francisco, CA'
|
29
|
+
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
|
30
|
+
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
|
31
|
+
|
32
32
|
@latlng = Geokit::LatLng.new(37.7742, -122.417068)
|
33
33
|
@success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>@latlng.lat, :lng=>@latlng.lng})
|
34
|
-
@success.success = true
|
35
|
-
end
|
36
|
-
|
34
|
+
@success.success = true
|
35
|
+
end
|
36
|
+
|
37
37
|
def test_timeout_call_web_service
|
38
38
|
url = "http://www.anything.com"
|
39
39
|
Geokit::Geocoders::request_timeout = 1
|
40
|
-
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
|
40
|
+
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def test_successful_call_web_service
|
44
44
|
url = "http://www.anything.com"
|
45
45
|
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
|
46
46
|
assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def test_find_geocoder_methods
|
50
50
|
public_methods = Geokit::Geocoders::Geocoder.public_methods.map { |m| m.to_s }
|
51
51
|
assert public_methods.include?("yahoo_geocoder")
|
data/test/test_bounds.rb
CHANGED
@@ -2,15 +2,15 @@ require 'test/unit'
|
|
2
2
|
require 'lib/geokit'
|
3
3
|
|
4
4
|
class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
7
|
# This is the area in Texas
|
8
8
|
@sw = Geokit::LatLng.new(32.91663,-96.982841)
|
9
9
|
@ne = Geokit::LatLng.new(32.96302,-96.919495)
|
10
|
-
@bounds=Geokit::Bounds.new(@sw,@ne)
|
11
|
-
@loc_a=Geokit::LatLng.new(32.918593,-96.958444) # inside bounds
|
10
|
+
@bounds=Geokit::Bounds.new(@sw,@ne)
|
11
|
+
@loc_a=Geokit::LatLng.new(32.918593,-96.958444) # inside bounds
|
12
12
|
@loc_b=Geokit::LatLng.new(32.914144,-96.958444) # outside bouds
|
13
|
-
|
13
|
+
|
14
14
|
# this is a cross-meridan area
|
15
15
|
@cross_meridian=Geokit::Bounds.normalize([30,170],[40,-170])
|
16
16
|
@inside_cm=Geokit::LatLng.new(35,175)
|
@@ -18,15 +18,15 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
|
18
18
|
@east_of_cm=Geokit::LatLng.new(35,-165)
|
19
19
|
@west_of_cm=Geokit::LatLng.new(35,165)
|
20
20
|
|
21
|
-
end
|
21
|
+
end
|
22
22
|
|
23
23
|
def test_equality
|
24
24
|
assert_equal Geokit::Bounds.new(@sw,@ne), Geokit::Bounds.new(@sw,@ne)
|
25
|
-
end
|
26
|
-
|
25
|
+
end
|
26
|
+
|
27
27
|
def test_normalize
|
28
28
|
res=Geokit::Bounds.normalize(@sw,@ne)
|
29
|
-
assert_equal res,Geokit::Bounds.new(@sw,@ne)
|
29
|
+
assert_equal res,Geokit::Bounds.new(@sw,@ne)
|
30
30
|
res=Geokit::Bounds.normalize([@sw,@ne])
|
31
31
|
assert_equal res,Geokit::Bounds.new(@sw,@ne)
|
32
32
|
res=Geokit::Bounds.normalize([@sw.lat,@sw.lng],[@ne.lat,@ne.lng])
|
@@ -34,14 +34,14 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
|
34
34
|
res=Geokit::Bounds.normalize([[@sw.lat,@sw.lng],[@ne.lat,@ne.lng]])
|
35
35
|
assert_equal res,Geokit::Bounds.new(@sw,@ne)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def test_point_inside_bounds
|
39
39
|
assert @bounds.contains?(@loc_a)
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_point_outside_bounds
|
43
|
-
assert !@bounds.contains?(@loc_b)
|
44
|
-
end
|
43
|
+
assert !@bounds.contains?(@loc_b)
|
44
|
+
end
|
45
45
|
|
46
46
|
def test_point_inside_bounds_cross_meridian
|
47
47
|
assert @cross_meridian.contains?(@inside_cm)
|
@@ -51,8 +51,8 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
|
51
51
|
def test_point_outside_bounds_cross_meridian
|
52
52
|
assert !@cross_meridian.contains?(@east_of_cm)
|
53
53
|
assert !@cross_meridian.contains?(@west_of_cm)
|
54
|
-
end
|
55
|
-
|
54
|
+
end
|
55
|
+
|
56
56
|
def test_center
|
57
57
|
assert_in_delta 32.939828,@bounds.center.lat,0.00005
|
58
58
|
assert_in_delta(-96.9511763,@bounds.center.lng,0.00005)
|
@@ -61,8 +61,8 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
|
61
61
|
def test_center_cross_meridian
|
62
62
|
assert_in_delta 35.41160, @cross_meridian.center.lat,0.00005
|
63
63
|
assert_in_delta 179.38112, @cross_meridian.center.lng,0.00005
|
64
|
-
end
|
65
|
-
|
64
|
+
end
|
65
|
+
|
66
66
|
def test_creation_from_circle
|
67
67
|
bounds=Geokit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
|
68
68
|
inside=Geokit::LatLng.new 32.9695270000,-96.9901590000
|
@@ -70,28 +70,28 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
|
|
70
70
|
assert bounds.contains?(inside)
|
71
71
|
assert !bounds.contains?(outside)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def test_bounds_to_span
|
75
75
|
sw = Geokit::LatLng.new(32, -96)
|
76
76
|
ne = Geokit::LatLng.new(40, -70)
|
77
77
|
bounds = Geokit::Bounds.new(sw, ne)
|
78
|
-
|
78
|
+
|
79
79
|
assert_equal Geokit::LatLng.new(8, 26), bounds.to_span
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def test_bounds_to_span_with_bounds_crossing_prime_meridian
|
83
83
|
sw = Geokit::LatLng.new(20, -70)
|
84
84
|
ne = Geokit::LatLng.new(40, 100)
|
85
85
|
bounds = Geokit::Bounds.new(sw, ne)
|
86
|
-
|
86
|
+
|
87
87
|
assert_equal Geokit::LatLng.new(20, 170), bounds.to_span
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def test_bounds_to_span_with_bounds_crossing_dateline
|
91
91
|
sw = Geokit::LatLng.new(20, 100)
|
92
92
|
ne = Geokit::LatLng.new(40, -70)
|
93
93
|
bounds = Geokit::Bounds.new(sw, ne)
|
94
|
-
|
94
|
+
|
95
95
|
assert_equal Geokit::LatLng.new(20, 190), bounds.to_span
|
96
96
|
end
|
97
|
-
end
|
97
|
+
end
|
data/test/test_ca_geocoder.rb
CHANGED
@@ -3,39 +3,39 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
|
3
3
|
Geokit::Geocoders::geocoder_ca = "SOMEKEYVALUE"
|
4
4
|
|
5
5
|
class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
6
|
+
|
7
7
|
CA_SUCCESS=<<-EOF
|
8
8
|
<?xml version="1.0" encoding="UTF-8" ?>
|
9
|
-
<geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
|
9
|
+
<geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
|
10
10
|
EOF
|
11
|
-
|
11
|
+
|
12
12
|
def setup
|
13
13
|
@ca_full_hash = {:street_address=>"2105 West 32nd Avenue",:city=>"Vancouver", :state=>"BC"}
|
14
14
|
@ca_full_loc = Geokit::GeoLoc.new(@ca_full_hash)
|
15
|
-
end
|
16
|
-
|
15
|
+
end
|
16
|
+
|
17
17
|
def test_geocoder_with_geo_loc_with_account
|
18
18
|
response = MockSuccess.new
|
19
19
|
response.expects(:body).returns(CA_SUCCESS)
|
20
20
|
url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
|
21
21
|
Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
22
|
-
verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
|
22
|
+
verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_service_unavailable
|
26
26
|
response = MockFailure.new
|
27
|
-
#Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
|
28
|
-
url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
|
27
|
+
#Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
|
28
|
+
url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
|
29
29
|
Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
30
|
-
assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
|
31
|
-
end
|
32
|
-
|
30
|
+
assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
|
31
|
+
end
|
32
|
+
|
33
33
|
private
|
34
|
-
|
34
|
+
|
35
35
|
def verify(location)
|
36
36
|
assert_equal "BC", location.state
|
37
|
-
assert_equal "Vancouver", location.city
|
38
|
-
assert_equal "49.243086,-123.153684", location.ll
|
39
|
-
assert !location.is_us?
|
37
|
+
assert_equal "Vancouver", location.city
|
38
|
+
assert_equal "49.243086,-123.153684", location.ll
|
39
|
+
assert !location.is_us?
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
data/test/test_geoloc.rb
CHANGED
@@ -2,17 +2,17 @@ require 'test/unit'
|
|
2
2
|
require 'lib/geokit'
|
3
3
|
|
4
4
|
class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
7
|
@loc = Geokit::GeoLoc.new
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def test_is_us
|
11
11
|
assert !@loc.is_us?
|
12
12
|
@loc.country_code = 'US'
|
13
13
|
assert @loc.is_us?
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_success
|
17
17
|
assert !@loc.success?
|
18
18
|
@loc.success = false
|
@@ -20,22 +20,22 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
|
20
20
|
@loc.success = true
|
21
21
|
assert @loc.success?
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def test_street_number
|
25
25
|
@loc.street_address = '123 Spear St.'
|
26
26
|
assert_equal '123', @loc.street_number
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def test_street_name
|
30
30
|
@loc.street_address = '123 Spear St.'
|
31
31
|
assert_equal 'Spear St.', @loc.street_name
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def test_city
|
35
35
|
@loc.city = "san francisco"
|
36
36
|
assert_equal 'San Francisco', @loc.city
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def test_full_address
|
40
40
|
@loc.city = 'San Francisco'
|
41
41
|
@loc.state = 'CA'
|
@@ -45,28 +45,28 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
|
|
45
45
|
@loc.full_address = 'Irving, TX, 75063, US'
|
46
46
|
assert_equal 'Irving, TX, 75063, US', @loc.full_address
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def test_hash
|
50
50
|
@loc.city = 'San Francisco'
|
51
51
|
@loc.state = 'CA'
|
52
52
|
@loc.zip = '94105'
|
53
53
|
@loc.country_code = 'US'
|
54
|
-
@another = Geokit::GeoLoc.new @loc.to_hash
|
54
|
+
@another = Geokit::GeoLoc.new @loc.to_hash
|
55
55
|
assert_equal @loc, @another
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def test_all
|
59
59
|
assert_equal [@loc], @loc.all
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_to_yaml
|
63
63
|
@loc.city = 'San Francisco'
|
64
64
|
@loc.state = 'CA'
|
65
65
|
@loc.zip = '94105'
|
66
66
|
@loc.country_code = 'US'
|
67
|
-
assert_equal(
|
68
|
-
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nstreet_name: \nstreet_number: \nsuccess: false\nzip: \"94105\"\n",
|
67
|
+
assert_equal(
|
68
|
+
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nstreet_name: \nstreet_number: \nsub_premise: \nsuccess: false\nzip: \"94105\"\n",
|
69
69
|
@loc.to_yaml)
|
70
70
|
end
|
71
|
-
|
72
|
-
end
|
71
|
+
|
72
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
3
3
|
|
4
4
|
class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
5
|
-
|
5
|
+
|
6
6
|
IP_SUCCESS=<<-EOF
|
7
7
|
<?xml version="1.0" encoding="UTF-8"?>
|
8
8
|
<geoPlugin>
|
@@ -24,8 +24,8 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
24
24
|
def setup
|
25
25
|
super
|
26
26
|
@success.provider = "geoPlugin"
|
27
|
-
end
|
28
|
-
|
27
|
+
end
|
28
|
+
|
29
29
|
def test_successful_lookup
|
30
30
|
success = MockSuccess.new
|
31
31
|
success.expects(:body).returns(IP_SUCCESS)
|
@@ -47,7 +47,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
47
47
|
assert_not_nil location
|
48
48
|
assert !location.success?
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def test_service_unavailable
|
52
52
|
failure = MockFailure.new
|
53
53
|
url = 'http://www.geoplugin.net/xml.gp?ip=10.10.10.10'
|
@@ -55,5 +55,5 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
55
55
|
location = GeoKit::Geocoders::GeoPluginGeocoder.geocode("10.10.10.10")
|
56
56
|
assert_not_nil location
|
57
57
|
assert !location.success?
|
58
|
-
end
|
58
|
+
end
|
59
59
|
end
|
@@ -3,11 +3,11 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
|
3
3
|
Geokit::Geocoders::google = 'Google'
|
4
4
|
|
5
5
|
class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
6
|
+
|
7
7
|
GOOGLE_FULL=<<-EOF.strip
|
8
8
|
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>100 spear st, san francisco, ca</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>100 Spear St, San Francisco, CA 94105, USA</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName><Thoroughfare><ThoroughfareName>100 Spear St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>94105</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.393985,37.792501,0</coordinates></Point></Placemark></Response></kml>
|
9
9
|
EOF
|
10
|
-
|
10
|
+
|
11
11
|
GOOGLE_RESULT_WITH_SUGGESTED_BOUNDS=<<-EOF.strip
|
12
12
|
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>100 spear st, san francisco, ca</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>100 Spear St, San Francisco, CA 94105, USA</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName><Thoroughfare><ThoroughfareName>100 Spear St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>94105</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="37.7956328" south="37.7893376" east="-122.3908573" west="-122.3971525" /></ExtendedData><Point><coordinates>-122.393985,37.792501,0</coordinates></Point></Placemark></Response></kml>
|
13
13
|
EOF
|
@@ -15,15 +15,15 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
15
15
|
GOOGLE_CITY=<<-EOF.strip
|
16
16
|
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>San Francisco</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>San Francisco, CA, USA</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName></Locality></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.418333,37.775000,0</coordinates></Point></Placemark></Response></kml>
|
17
17
|
EOF
|
18
|
-
|
18
|
+
|
19
19
|
GOOGLE_MULTI="<?xml version='1.0' encoding='UTF-8'?>\n<kml xmlns='http://earth.google.com/kml/2.0'><Response>\n <name>via Sandro Pertini 8, Ossona, MI</name>\n <Status>\n <code>200</code>\n <request>geocode</request>\n </Status>\n <Placemark id='p1'>\n <address>Via Sandro Pertini, 8, 20010 Mesero MI, Italy</address>\n <AddressDetails Accuracy='8' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>IT</CountryNameCode><CountryName>Italy</CountryName><AdministrativeArea><AdministrativeAreaName>Lombardy</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Milan</SubAdministrativeAreaName><Locality><LocalityName>Mesero</LocalityName><Thoroughfare><ThoroughfareName>8 Via Sandro Pertini</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>20010</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>\n <Point><coordinates>8.8527131,45.4966243,0</coordinates></Point>\n </Placemark>\n <Placemark id='p2'>\n <address>Via Sandro Pertini, 20010 Ossona MI, Italy</address>\n <AddressDetails Accuracy='6' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>IT</CountryNameCode><CountryName>Italy</CountryName><AdministrativeArea><AdministrativeAreaName>Lombardy</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Milan</SubAdministrativeAreaName><Locality><LocalityName>Ossona</LocalityName><Thoroughfare><ThoroughfareName>Via Sandro Pertini</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>20010</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>\n <Point><coordinates>8.9023200,45.5074444,0</coordinates></Point>\n </Placemark>\n</Response></kml>\n"
|
20
|
-
|
20
|
+
|
21
21
|
GOOGLE_REVERSE_MADRID="<?xml version='1.0' encoding='UTF-8' ?><kml xmlns='http://earth.google.com/kml/2.0'><Response><name>40.416741,-3.703250</name><Status><code>200</code><request>geocode</request></Status><Placemark id='p1'><address>Plaza de la Puerta del Sol, 28013, Madrid, Spain</address><AddressDetails Accuracy='6' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>ES</CountryNameCode><CountryName>Spain</CountryName><AdministrativeArea><AdministrativeAreaName>Madrid</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Madrid</SubAdministrativeAreaName><Locality><LocalityName>Madrid</LocalityName><Thoroughfare><ThoroughfareName>Plaza de la Puerta del Sol</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>28013</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north='40.4199522' south='40.4136570' east='-3.7001138' west='-3.7064091' /></ExtendedData><Point><coordinates>-3.7032537,40.4168023,0</coordinates></Point></Placemark><Placemark id='p2'><address>28013, Madrid, Spain</address><AddressDetails Accuracy='5' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>ES</CountryNameCode><CountryName>Spain</CountryName><AdministrativeArea><AdministrativeAreaName>Madrid</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Madrid</SubAdministrativeAreaName><Locality><LocalityName>Madrid</LocalityName><PostalCode><PostalCodeNumber>28013</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north='40.4244113' south='40.4142840' east='-3.6969862' west='-3.7224820' /></ExtendedData><Point><coordinates>-3.7117806,40.4189645,0</coordinates></Point></Placemark><Placemark id='p3'><address>Madrid, Spain</address><AddressDetails Accuracy='4' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>ES</CountryNameCode><CountryName>Spain</CountryName><AdministrativeArea><AdministrativeAreaName>Madrid</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Madrid</SubAdministrativeAreaName><Locality><LocalityName>Madrid</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north='40.6435181' south='40.3120713' east='-3.5180102' west='-3.8890049' /></ExtendedData><Point><coordinates>-3.7032498,40.4167413,0</coordinates></Point></Placemark><Placemark id='p4'><address>Madrid, Spain</address><AddressDetails Accuracy='2' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>ES</CountryNameCode><CountryName>Spain</CountryName><AdministrativeArea><AdministrativeAreaName>Madrid</AdministrativeAreaName></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north='41.1649106' south='39.8845366' east='-3.0531322' west='-4.5791745' /></ExtendedData><Point><coordinates>-3.5812692,40.4167088,0</coordinates></Point></Placemark><Placemark id='p5'><address>Madrid, Spain</address><AddressDetails Accuracy='3' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>ES</CountryNameCode><CountryName>Spain</CountryName><AdministrativeArea><AdministrativeAreaName>Madrid</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Madrid</SubAdministrativeAreaName></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north='41.1649106' south='39.8845366' east='-3.0531322' west='-4.5791745' /></ExtendedData><Point><coordinates>-3.5812692,40.4167088,0</coordinates></Point></Placemark><Placemark id='p6'><address>Spain</address><AddressDetails Accuracy='1' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>ES</CountryNameCode><CountryName>Spain</CountryName></Country></AddressDetails><ExtendedData><LatLonBox north='43.7903881' south='27.6377504' east='4.3279851' west='-18.1606948' /></ExtendedData><Point><coordinates>-3.7492200,40.4636670,0</coordinates></Point></Placemark></Response></kml>"
|
22
|
-
|
22
|
+
|
23
23
|
GOOGLE_COUNTRY_CODE_BIASED_RESULT = <<-EOF.strip
|
24
24
|
<?xml version="1.0" encoding="UTF-8" ?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>Syracuse</name><Status><code>200</code><request>geocode</request></Status><Placemark id="p1"><address>Syracuse, Italy</address><AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>IT</CountryNameCode><CountryName>Italy</CountryName><AdministrativeArea><AdministrativeAreaName>Sicily</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Syracuse</SubAdministrativeAreaName></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="37.4125978" south="36.6441736" east="15.3367367" west="14.7724913" /></ExtendedData><Point><coordinates>14.9856176,37.0630218,0</coordinates></Point></Placemark></Response></kml>
|
25
25
|
EOF
|
26
|
-
|
26
|
+
|
27
27
|
GOOGLE_BOUNDS_BIASED_RESULT = <<-EOF.strip
|
28
28
|
<?xml version="1.0" encoding="UTF-8" ?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>Winnetka</name><Status><code>200</code><request>geocode</request></Status><Placemark id="p1"><address>Winnetka, California, USA</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><AddressLine>Winnetka</AddressLine></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="34.2353090" south="34.1791050" east="-118.5534191" west="-118.5883200" /></ExtendedData><Point><coordinates>-118.5710220,34.2131710,0</coordinates></Point></Placemark></Response></kml>
|
29
29
|
EOF
|
@@ -31,7 +31,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
31
31
|
GOOGLE_TOO_MANY=<<-EOF.strip
|
32
32
|
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>100 spear st, san francisco, ca</name><Status><code>620</code><request>geocode</request></Status></Response></kml>
|
33
33
|
EOF
|
34
|
-
|
34
|
+
|
35
35
|
def setup
|
36
36
|
super
|
37
37
|
@google_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
|
@@ -39,7 +39,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
39
39
|
|
40
40
|
@google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
|
41
41
|
@google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
|
42
|
-
end
|
42
|
+
end
|
43
43
|
|
44
44
|
def test_google_full_address
|
45
45
|
response = MockSuccess.new
|
@@ -48,13 +48,13 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
48
48
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
49
49
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
50
50
|
assert_equal "CA", res.state
|
51
|
-
assert_equal "San Francisco", res.city
|
51
|
+
assert_equal "San Francisco", res.city
|
52
52
|
assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
|
53
53
|
assert res.is_us?
|
54
54
|
assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
|
55
55
|
assert_equal "google", res.provider
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def test_google_full_address_with_geo_loc
|
59
59
|
response = MockSuccess.new
|
60
60
|
response.expects(:body).returns(GOOGLE_FULL)
|
@@ -62,13 +62,13 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
62
62
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
63
63
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
64
64
|
assert_equal "CA", res.state
|
65
|
-
assert_equal "San Francisco", res.city
|
65
|
+
assert_equal "San Francisco", res.city
|
66
66
|
assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
|
67
67
|
assert res.is_us?
|
68
68
|
assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
|
69
69
|
assert_equal "google", res.provider
|
70
|
-
end
|
71
|
-
|
70
|
+
end
|
71
|
+
|
72
72
|
def test_google_full_address_accuracy
|
73
73
|
response = MockSuccess.new
|
74
74
|
response.expects(:body).returns(GOOGLE_FULL)
|
@@ -91,8 +91,8 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
91
91
|
assert_equal "San Francisco, CA, USA", res.full_address
|
92
92
|
assert_nil res.street_address
|
93
93
|
assert_equal "google", res.provider
|
94
|
-
end
|
95
|
-
|
94
|
+
end
|
95
|
+
|
96
96
|
def test_google_city_accuracy
|
97
97
|
response = MockSuccess.new
|
98
98
|
response.expects(:body).returns(GOOGLE_CITY)
|
@@ -101,7 +101,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
101
101
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
102
102
|
assert_equal 4, res.accuracy
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def test_google_city_with_geo_loc
|
106
106
|
response = MockSuccess.new
|
107
107
|
response.expects(:body).returns(GOOGLE_CITY)
|
@@ -115,26 +115,26 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
115
115
|
assert_equal "San Francisco, CA, USA", res.full_address
|
116
116
|
assert_nil res.street_address
|
117
117
|
assert_equal "google", res.provider
|
118
|
-
end
|
119
|
-
|
118
|
+
end
|
119
|
+
|
120
120
|
def test_google_suggested_bounds
|
121
121
|
response = MockSuccess.new
|
122
122
|
response.expects(:body).returns(GOOGLE_RESULT_WITH_SUGGESTED_BOUNDS)
|
123
123
|
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
|
124
124
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
125
125
|
res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
126
|
-
|
126
|
+
|
127
127
|
assert_instance_of Geokit::Bounds, res.suggested_bounds
|
128
128
|
assert_equal Geokit::Bounds.new(Geokit::LatLng.new(37.7893376, -122.3971525), Geokit::LatLng.new(37.7956328, -122.3908573)), res.suggested_bounds
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
def test_service_unavailable
|
132
132
|
response = MockFailure.new
|
133
133
|
url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
|
134
134
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
135
135
|
assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
|
136
|
-
end
|
137
|
-
|
136
|
+
end
|
137
|
+
|
138
138
|
def test_multiple_results
|
139
139
|
#Geokit::Geocoders::GoogleGeocoder.do_geocode('via Sandro Pertini 8, Ossona, MI')
|
140
140
|
response = MockSuccess.new
|
@@ -187,30 +187,30 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
187
187
|
assert_equal "Plaza de la Puerta del Sol, 28013, Madrid, Spain", res.full_address
|
188
188
|
assert_equal "28013", res.zip
|
189
189
|
assert_equal "Plaza de la Puerta del Sol", res.street_address
|
190
|
-
end
|
191
|
-
|
190
|
+
end
|
191
|
+
|
192
192
|
def test_country_code_biasing
|
193
193
|
response = MockSuccess.new
|
194
194
|
response.expects(:body).returns(GOOGLE_COUNTRY_CODE_BIASED_RESULT)
|
195
|
-
|
195
|
+
|
196
196
|
url = "http://maps.google.com/maps/geo?q=Syracuse&output=xml&gl=it&key=Google&oe=utf-8"
|
197
197
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
198
198
|
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
|
199
|
-
|
199
|
+
|
200
200
|
assert_equal 'IT', biased_result.country_code
|
201
201
|
assert_equal 'Sicily', biased_result.state
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
def test_bounds_biasing
|
205
205
|
response = MockSuccess.new
|
206
206
|
response.expects(:body).returns(GOOGLE_BOUNDS_BIASED_RESULT)
|
207
|
-
|
207
|
+
|
208
208
|
url = "http://maps.google.com/maps/geo?q=Winnetka&output=xml&ll=34.197693208849,-118.547160027785&spn=0.247047999999999,0.294914000000006&key=Google&oe=utf-8"
|
209
209
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
210
|
-
|
210
|
+
|
211
211
|
bounds = Geokit::Bounds.normalize([34.074081, -118.694401], [34.321129, -118.399487])
|
212
212
|
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => bounds)
|
213
|
-
|
213
|
+
|
214
214
|
assert_equal 'US', biased_result.country_code
|
215
215
|
assert_equal 'CA', biased_result.state
|
216
216
|
end
|