geokit-premier 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,227 @@
1
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
2
+
3
+ Geokit::Geocoders::google = 'Google'
4
+
5
+ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
6
+
7
+ GOOGLE_FULL=<<-EOF.strip
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
+ EOF
10
+
11
+ GOOGLE_RESULT_WITH_SUGGESTED_BOUNDS=<<-EOF.strip
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
+ EOF
14
+
15
+ GOOGLE_CITY=<<-EOF.strip
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
+ EOF
18
+
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
+
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
+
23
+ GOOGLE_COUNTRY_CODE_BIASED_RESULT = <<-EOF.strip
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
+ EOF
26
+
27
+ GOOGLE_BOUNDS_BIASED_RESULT = <<-EOF.strip
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
+ EOF
30
+
31
+ GOOGLE_TOO_MANY=<<-EOF.strip
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
+ EOF
34
+
35
+ def setup
36
+ super
37
+ @google_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
38
+ @google_city_hash = {:city=>"San Francisco", :state=>"CA"}
39
+
40
+ @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
41
+ @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
42
+ end
43
+
44
+ def test_google_full_address
45
+ response = MockSuccess.new
46
+ response.expects(:body).returns(GOOGLE_FULL)
47
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
48
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
49
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
50
+ assert_equal "CA", res.state
51
+ assert_equal "San Francisco", res.city
52
+ assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
53
+ assert res.is_us?
54
+ assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
55
+ assert_equal "google", res.provider
56
+ end
57
+
58
+ def test_google_full_address_with_geo_loc
59
+ response = MockSuccess.new
60
+ response.expects(:body).returns(GOOGLE_FULL)
61
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
62
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
63
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
64
+ assert_equal "CA", res.state
65
+ assert_equal "San Francisco", res.city
66
+ assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
67
+ assert res.is_us?
68
+ assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
69
+ assert_equal "google", res.provider
70
+ end
71
+
72
+ def test_google_full_address_accuracy
73
+ response = MockSuccess.new
74
+ response.expects(:body).returns(GOOGLE_FULL)
75
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
76
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
77
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
78
+ assert_equal 8, res.accuracy
79
+ end
80
+
81
+ def test_google_city
82
+ response = MockSuccess.new
83
+ response.expects(:body).returns(GOOGLE_CITY)
84
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
85
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
86
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
87
+ assert_equal "CA", res.state
88
+ assert_equal "San Francisco", res.city
89
+ assert_equal "37.775,-122.418333", res.ll
90
+ assert res.is_us?
91
+ assert_equal "San Francisco, CA, USA", res.full_address
92
+ assert_nil res.street_address
93
+ assert_equal "google", res.provider
94
+ end
95
+
96
+ def test_google_city_accuracy
97
+ response = MockSuccess.new
98
+ response.expects(:body).returns(GOOGLE_CITY)
99
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
100
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
101
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
102
+ assert_equal 4, res.accuracy
103
+ end
104
+
105
+ def test_google_city_with_geo_loc
106
+ response = MockSuccess.new
107
+ response.expects(:body).returns(GOOGLE_CITY)
108
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
109
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
110
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
111
+ assert_equal "CA", res.state
112
+ assert_equal "San Francisco", res.city
113
+ assert_equal "37.775,-122.418333", res.ll
114
+ assert res.is_us?
115
+ assert_equal "San Francisco, CA, USA", res.full_address
116
+ assert_nil res.street_address
117
+ assert_equal "google", res.provider
118
+ end
119
+
120
+ def test_google_suggested_bounds
121
+ response = MockSuccess.new
122
+ response.expects(:body).returns(GOOGLE_RESULT_WITH_SUGGESTED_BOUNDS)
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
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
125
+ res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
126
+
127
+ assert_instance_of Geokit::Bounds, res.suggested_bounds
128
+ assert_equal Geokit::Bounds.new(Geokit::LatLng.new(37.7893376, -122.3971525), Geokit::LatLng.new(37.7956328, -122.3908573)), res.suggested_bounds
129
+ end
130
+
131
+ def test_service_unavailable
132
+ response = MockFailure.new
133
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
134
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
135
+ assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
136
+ end
137
+
138
+ def test_multiple_results
139
+ #Geokit::Geocoders::GoogleGeocoder.do_geocode('via Sandro Pertini 8, Ossona, MI')
140
+ response = MockSuccess.new
141
+ response.expects(:body).returns(GOOGLE_MULTI)
142
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}&output=xml&key=Google&oe=utf-8"
143
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
144
+ res=Geokit::Geocoders::GoogleGeocoder.geocode('via Sandro Pertini 8, Ossona, MI')
145
+ assert_equal "Lombardy", res.state
146
+ assert_equal "Mesero", res.city
147
+ assert_equal "45.4966243,8.8527131", res.ll
148
+ assert !res.is_us?
149
+ assert_equal "Via Sandro Pertini, 8, 20010 Mesero MI, Italy", res.full_address
150
+ assert_equal "8 Via Sandro Pertini", res.street_address
151
+ assert_equal "google", res.provider
152
+
153
+ assert_equal 2, res.all.size
154
+ res = res.all[1]
155
+ assert_equal "Lombardy", res.state
156
+ assert_equal "Ossona", res.city
157
+ assert_equal "45.5074444,8.90232", res.ll
158
+ assert !res.is_us?
159
+ assert_equal "Via Sandro Pertini, 20010 Ossona MI, Italy", res.full_address
160
+ assert_equal "Via Sandro Pertini", res.street_address
161
+ assert_equal "google", res.provider
162
+ end
163
+
164
+ def test_reverse_geocode
165
+ #Geokit::Geocoders::GoogleGeocoder.do_reverse_geocode("40.4167413, -3.7032498")
166
+ madrid = Geokit::GeoLoc.new
167
+ madrid.lat, madrid.lng = "40.4167413", "-3.7032498"
168
+ response = MockSuccess.new
169
+ response.expects(:body).returns(GOOGLE_REVERSE_MADRID)
170
+ url = "http://maps.google.com/maps/geo?ll=#{Geokit::Inflector::url_escape(madrid.ll)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8"
171
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).
172
+ returns(response)
173
+ res=Geokit::Geocoders::GoogleGeocoder.do_reverse_geocode(madrid.ll)
174
+
175
+ assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
176
+ assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
177
+ assert_equal "ES", res.country_code
178
+ assert_equal "google", res.provider
179
+
180
+ assert_equal "Madrid", res.city
181
+ assert_equal "Madrid", res.state
182
+
183
+ assert_equal "Spain", res.country
184
+ assert_equal "zip+4", res.precision
185
+ assert_equal true, res.success
186
+
187
+ assert_equal "Plaza de la Puerta del Sol, 28013, Madrid, Spain", res.full_address
188
+ assert_equal "28013", res.zip
189
+ assert_equal "Plaza De La Puerta Del Sol", res.street_address
190
+ end
191
+
192
+ def test_country_code_biasing
193
+ response = MockSuccess.new
194
+ response.expects(:body).returns(GOOGLE_COUNTRY_CODE_BIASED_RESULT)
195
+
196
+ url = "http://maps.google.com/maps/geo?q=Syracuse&output=xml&gl=it&key=Google&oe=utf-8"
197
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
198
+ biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
199
+
200
+ assert_equal 'IT', biased_result.country_code
201
+ assert_equal 'Sicily', biased_result.state
202
+ end
203
+
204
+ def test_bounds_biasing
205
+ response = MockSuccess.new
206
+ response.expects(:body).returns(GOOGLE_BOUNDS_BIASED_RESULT)
207
+
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
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
210
+
211
+ bounds = Geokit::Bounds.normalize([34.074081, -118.694401], [34.321129, -118.399487])
212
+ biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => bounds)
213
+
214
+ assert_equal 'US', biased_result.country_code
215
+ assert_equal 'CA', biased_result.state
216
+ end
217
+
218
+ def test_too_many_queries
219
+ response = MockSuccess.new
220
+ response.expects(:body).returns(GOOGLE_TOO_MANY)
221
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
222
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
223
+ assert_raise Geokit::TooManyQueriesError do
224
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
2
+
3
+ Geokit::Geocoders::google = 'Google'
4
+
5
+ class GoogleReverseGeocoderTest < BaseGeocoderTest #:nodoc: all
6
+
7
+ GOOGLE_REVERSE_FULL=<<-EOF.strip
8
+ <?xml version="1.0" encoding="UTF-8" ?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>51.457833,7.016685</name><Status><code>200</code><request>geocode</request></Status><Placemark id="p1"><address>Porscheplatz 1, 45127 Essen, Deutschland</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName><DependentLocality><DependentLocalityName>Stadtkern</DependentLocalityName><Thoroughfare><ThoroughfareName>Porscheplatz 1</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>45127</PostalCodeNumber></PostalCode></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.4609805" south="51.4546853" east="7.0198324" west="7.0135372" /></ExtendedData><Point><coordinates>7.0166848,51.4578329,0</coordinates></Point></Placemark><Placemark id="p2"><address>Stadtkern, Essen, Deutschland</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName><DependentLocality><DependentLocalityName>Stadtkern</DependentLocalityName></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.4630710" south="51.4506320" east="7.0193200" west="7.0026170" /></ExtendedData><Point><coordinates>7.0124328,51.4568201,0</coordinates></Point></Placemark><Placemark id="p3"><address>45127 Essen, Deutschland</address><AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName><PostalCode><PostalCodeNumber>45127</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.4637808" south="51.4503125" east="7.0231080" west="6.9965454" /></ExtendedData><Point><coordinates>7.0104543,51.4556194,0</coordinates></Point></Placemark><Placemark id="p4"><address>Essen, Deutschland</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.5342070" south="51.3475730" east="7.1376530" west="6.8943470" /></ExtendedData><Point><coordinates>7.0147614,51.4580686,0</coordinates></Point></Placemark><Placemark id="p5"><address>Essen, Deutschland</address><AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.5342070" south="51.3475730" east="7.1376530" west="6.8943470" /></ExtendedData><Point><coordinates>7.0461136,51.4508381,0</coordinates></Point></Placemark><Placemark id="p6"><address>Nordrhein-Westfalen, Deutschland</address><AddressDetails Accuracy="2" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="52.5314170" south="50.3225720" east="9.4615950" west="5.8663566" /></ExtendedData><Point><coordinates>7.6615938,51.4332367,0</coordinates></Point></Placemark><Placemark id="p7"><address>Deutschland</address><AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName></Country></AddressDetails><ExtendedData><LatLonBox north="55.0568230" south="47.2701270" east="15.0418536" west="5.8663566" /></ExtendedData><Point><coordinates>10.4515260,51.1656910,0</coordinates></Point></Placemark></Response></kml>
9
+ EOF
10
+
11
+
12
+ def test_google_full_address
13
+ response = MockSuccess.new
14
+ response.expects(:body).returns(GOOGLE_REVERSE_FULL)
15
+
16
+
17
+ # http://maps.google.com/maps/geo?output=xml&oe=utf-8&ll=51.4578329,7.0166848&key=asdad
18
+
19
+ # #<Geokit::GeoLoc:0x10ec7ec
20
+ # @city="Essen",
21
+ # @country_code="DE",
22
+ # @full_address="Porscheplatz 1, 45127 Essen, Germany",
23
+ # @lat=51.4578329,
24
+ # @lng=7.0166848,
25
+ # @precision="address",
26
+ # @provider="google",
27
+ # @state="Nordrhein-Westfalen",
28
+ # @street_address="Porscheplatz 1",
29
+ # @success=true,
30
+ # @zip="45127">
31
+ #
32
+
33
+
34
+ @latlng = "51.4578329,7.0166848"
35
+
36
+ url = "http://maps.google.com/maps/geo?ll=#{Geokit::Inflector.url_escape(@latlng)}&output=xml&key=Google&oe=utf-8"
37
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
38
+ res=Geokit::Geocoders::GoogleGeocoder.reverse_geocode(@latlng)
39
+ assert_equal "Nordrhein-Westfalen", res.state
40
+ assert_equal "Essen", res.city
41
+ assert_equal "45127", res.zip
42
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
43
+ assert res.is_us? == false
44
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
45
+ assert_equal "google", res.provider
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/unit'
4
+ require 'lib/geokit'
5
+
6
+ class InflectorTest < Test::Unit::TestCase #:nodoc: all
7
+
8
+ def test_titleize
9
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar Grove')
10
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar grove')
11
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('sugar Grove')
12
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('sugar grove')
13
+ end
14
+
15
+ def test_titleize_with_unicode
16
+ assert_equal 'Borås', Geokit::Inflector.titleize('Borås')
17
+ assert_equal 'Borås', Geokit::Inflector.titleize('borås')
18
+ assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('Borås (Abc)')
19
+ assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('Borås (abc)')
20
+ assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('borås (Abc)')
21
+ assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('borås (abc)')
22
+ end
23
+
24
+ end
@@ -0,0 +1,110 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
3
+
4
+ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
+
6
+ IP_FAILURE=<<-EOF
7
+ Country: SWITZERLAND (CH)
8
+ City: (Unknown City)
9
+ Latitude:
10
+ Longitude:
11
+ EOF
12
+
13
+ IP_SUCCESS=<<-EOF
14
+ Country: UNITED STATES (US)
15
+ City: Sugar Grove, IL
16
+ Latitude: 41.7696
17
+ Longitude: -88.4588
18
+ EOF
19
+
20
+ IP_UNICODED=<<-EOF
21
+ Country: SWEDEN (SE)
22
+ City: Borås
23
+ Latitude: 57.7167
24
+ Longitude: 12.9167
25
+ EOF
26
+
27
+ PRIVATE_IPS_TO_TEST = [
28
+ '10.10.10.10',
29
+ '172.16.1.3',
30
+ '172.22.3.42',
31
+ '172.30.254.164',
32
+ '192.168.1.1',
33
+ '0.0.0.0',
34
+ '127.0.0.1',
35
+ '240.3.4.5',
36
+ '225.1.6.55'
37
+ ].freeze
38
+
39
+ def setup
40
+ super
41
+ @success.provider = "hostip"
42
+ end
43
+
44
+ def test_successful_lookup
45
+ success = MockSuccess.new
46
+ success.expects(:body).returns(IP_SUCCESS)
47
+ url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
48
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
49
+ location = GeoKit::Geocoders::IpGeocoder.geocode('12.215.42.19')
50
+ assert_not_nil location
51
+ assert_equal 41.7696, location.lat
52
+ assert_equal(-88.4588, location.lng)
53
+ assert_equal "Sugar Grove", location.city
54
+ assert_equal "IL", location.state
55
+ assert_equal "US", location.country_code
56
+ assert_equal "hostip", location.provider
57
+ assert location.success?
58
+ end
59
+
60
+ def test_unicoded_lookup
61
+ success = MockSuccess.new
62
+ success.expects(:body).returns(IP_UNICODED)
63
+ url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
64
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
65
+ location = GeoKit::Geocoders::IpGeocoder.geocode('12.215.42.19')
66
+ assert_not_nil location
67
+ assert_equal 57.7167, location.lat
68
+ assert_equal 12.9167, location.lng
69
+ assert_equal "Bor\303\245s", location.city
70
+ assert_nil location.state
71
+ assert_equal "SE", location.country_code
72
+ assert_equal "hostip", location.provider
73
+ assert location.success?
74
+ end
75
+
76
+ def test_failed_lookup
77
+ failure = MockSuccess.new
78
+ failure.expects(:body).returns(IP_FAILURE)
79
+ url = 'http://api.hostip.info/get_html.php?ip=128.178.0.0&position=true'
80
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
81
+ location = GeoKit::Geocoders::IpGeocoder.geocode("128.178.0.0")
82
+ assert_not_nil location
83
+ assert !location.success?
84
+ end
85
+
86
+ def test_private_ips
87
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never
88
+ PRIVATE_IPS_TO_TEST.each do |ip|
89
+ location = GeoKit::Geocoders::IpGeocoder.geocode(ip)
90
+ assert_not_nil location
91
+ assert !location.success?
92
+ end
93
+ end
94
+
95
+ def test_invalid_ip
96
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never
97
+ location = GeoKit::Geocoders::IpGeocoder.geocode("blah")
98
+ assert_not_nil location
99
+ assert !location.success?
100
+ end
101
+
102
+ def test_service_unavailable
103
+ failure = MockFailure.new
104
+ url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
105
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
106
+ location = GeoKit::Geocoders::IpGeocoder.geocode("12.215.42.19")
107
+ assert_not_nil location
108
+ assert !location.success?
109
+ end
110
+ end
@@ -0,0 +1,209 @@
1
+ require 'test/unit'
2
+ require 'lib/geokit'
3
+ require 'mocha'
4
+
5
+ class LatLngTest < Test::Unit::TestCase #:nodoc: all
6
+
7
+ def setup
8
+ @loc_a = Geokit::LatLng.new(32.918593,-96.958444)
9
+ @loc_e = Geokit::LatLng.new(32.969527,-96.990159)
10
+ @point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
11
+ end
12
+
13
+ def valid_reverse_geocoding_result
14
+ location = Geokit::GeoLoc.new({
15
+ :city => "Essen",
16
+ :country_code => "DE",
17
+ :lat => 51.4578329,
18
+ :lng => 7.0166848,
19
+ :provider => "google",
20
+ :state => "Nordrhein-Westfalen",
21
+ :street_address => "Porscheplatz 1",
22
+ :zip => "45127"
23
+ })
24
+
25
+ location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland"
26
+ location.precision = 'address'
27
+ location.provider = 'google'
28
+ location.success = true
29
+ location
30
+ end
31
+
32
+ def test_distance_between_same_using_defaults
33
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
34
+ assert_equal 0, @loc_a.distance_to(@loc_a)
35
+ end
36
+
37
+ def test_distance_between_same_with_miles_and_flat
38
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :flat)
39
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :flat)
40
+ end
41
+
42
+ def test_distance_between_same_with_kms_and_flat
43
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :flat)
44
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :flat)
45
+ end
46
+
47
+ def test_distance_between_same_with_nms_and_flat
48
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :flat)
49
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :flat)
50
+ end
51
+
52
+ def test_distance_between_same_with_miles_and_sphere
53
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :sphere)
54
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :sphere)
55
+ end
56
+
57
+ def test_distance_between_same_with_kms_and_sphere
58
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :sphere)
59
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :sphere)
60
+ end
61
+
62
+ def test_distance_between_same_with_nms_and_sphere
63
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :sphere)
64
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :sphere)
65
+ end
66
+
67
+ def test_distance_between_diff_using_defaults
68
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e), 0.01
69
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e), 0.01
70
+ end
71
+
72
+ def test_distance_between_diff_with_miles_and_flat
73
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :flat), 0.2
74
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
75
+ end
76
+
77
+ def test_distance_between_diff_with_kms_and_flat
78
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :flat), 0.4
79
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
80
+ end
81
+
82
+ def test_distance_between_diff_with_nms_and_flat
83
+ assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :flat), 0.4
84
+ assert_in_delta 3.334, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
85
+ end
86
+
87
+ def test_distance_between_diff_with_miles_and_sphere
88
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :sphere), 0.01
89
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :sphere), 0.01
90
+ end
91
+
92
+ def test_distance_between_diff_with_kms_and_sphere
93
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :sphere), 0.01
94
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :sphere), 0.01
95
+ end
96
+
97
+ def test_distance_between_diff_with_nms_and_sphere
98
+ assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :sphere), 0.01
99
+ assert_in_delta 3.454, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :sphere), 0.01
100
+ end
101
+
102
+ def test_manually_mixed_in
103
+ assert_equal 0, Geokit::LatLng.distance_between(@point, @point)
104
+ assert_equal 0, @point.distance_to(@point)
105
+ assert_equal 0, @point.distance_to(@loc_a)
106
+ assert_in_delta 3.97, @point.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
107
+ assert_in_delta 6.39, @point.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
108
+ assert_in_delta 3.334, @point.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
109
+ end
110
+
111
+ def test_heading_between
112
+ assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a,@loc_e), 0.5
113
+ end
114
+
115
+ def test_heading_to
116
+ assert_in_delta 332, @loc_a.heading_to(@loc_e), 0.5
117
+ end
118
+
119
+ def test_class_endpoint
120
+ endpoint=Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
121
+ assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
122
+ assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
123
+ end
124
+
125
+ def test_instance_endpoint
126
+ endpoint=@loc_a.endpoint(332, 3.97)
127
+ assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
128
+ assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
129
+ end
130
+
131
+ def test_midpoint
132
+ midpoint=@loc_a.midpoint_to(@loc_e)
133
+ assert_in_delta 32.944061, midpoint.lat, 0.0005
134
+ assert_in_delta(-96.974296, midpoint.lng, 0.0005)
135
+ end
136
+
137
+ def test_normalize
138
+ lat=37.7690
139
+ lng=-122.443
140
+ res=Geokit::LatLng.normalize(lat,lng)
141
+ assert_equal res,Geokit::LatLng.new(lat,lng)
142
+ res=Geokit::LatLng.normalize("#{lat}, #{lng}")
143
+ assert_equal res,Geokit::LatLng.new(lat,lng)
144
+ res=Geokit::LatLng.normalize("#{lat} #{lng}")
145
+ assert_equal res,Geokit::LatLng.new(lat,lng)
146
+ res=Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
147
+ assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
148
+ res=Geokit::LatLng.normalize([lat,lng])
149
+ assert_equal res,Geokit::LatLng.new(lat,lng)
150
+ end
151
+
152
+ def test_hash
153
+ lat=37.7690
154
+ lng=-122.443
155
+ first = Geokit::LatLng.new(lat,lng)
156
+ second = Geokit::LatLng.new(lat,lng)
157
+ assert_equal first.hash, second.hash
158
+ end
159
+
160
+ def test_eql?
161
+ lat=37.7690
162
+ lng=-122.443
163
+ first = Geokit::LatLng.new(lat,lng)
164
+ second = Geokit::LatLng.new(lat,lng)
165
+ assert first.eql?(second)
166
+ assert second.eql?(first)
167
+ end
168
+
169
+ def test_reverse_geocode
170
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
171
+ Geokit::Geocoders::MultiGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
172
+ res = point.reverse_geocode
173
+
174
+ assert_equal "Nordrhein-Westfalen", res.state
175
+ assert_equal "Essen", res.city
176
+ assert_equal "45127", res.zip
177
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
178
+ assert res.is_us? == false
179
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
180
+ end
181
+
182
+ def test_reverse_geocoding_using_specific_geocoder
183
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
184
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
185
+ res = point.reverse_geocode(:using => Geokit::Geocoders::GoogleGeocoder)
186
+
187
+ assert_equal "Nordrhein-Westfalen", res.state
188
+ assert_equal "Essen", res.city
189
+ assert_equal "45127", res.zip
190
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
191
+ assert res.is_us? == false
192
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
193
+ assert_equal "google", res.provider
194
+ end
195
+
196
+ def test_reverse_geocoding_using_specific_geocoder_short_syntax
197
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
198
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
199
+ res = point.reverse_geocode(:using => :google)
200
+
201
+ assert_equal "Nordrhein-Westfalen", res.state
202
+ assert_equal "Essen", res.city
203
+ assert_equal "45127", res.zip
204
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
205
+ assert res.is_us? == false
206
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
207
+ assert_equal "google", res.provider
208
+ end
209
+ end