Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1949305

Browse files
committed
Merge commit 'fcdd2d7'
Conflicts: lib/geocoder.rb
2 parents 0678ae8 + fcdd2d7 commit 1949305

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

README.rdoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Street address geocoding services currently supported (valid settings for the ab
227227
* Google: <tt>:google</tt>
228228
* Yahoo: <tt>:yahoo</tt>
229229
* Geocoder.ca: <tt>:geocoder_ca</tt> (US and Canada only)
230+
* Bing: <tt>:bing</tt>
230231

231232
Note that the result objects returned by different geocoding services all implement the methods listed above. Beyond that, however, you must be familiar with your particular subclass of <tt>Geocoder::Result</tt> and the geocoding service's result structure:
232233

@@ -235,7 +236,7 @@ Note that the result objects returned by different geocoding services all implem
235236
* Geocoder.ca: (???)
236237
* Yandex: http://api.yandex.ru/maps/geocoder/doc/desc/concepts/response_structure.xml
237238
* FreeGeoIP: http://github.com/fiorix/freegeoip/blob/master/README.rst
238-
239+
* Bing: http://msdn.microsoft.com/en-us/library/ff701715.aspx
239240
=== API Keys
240241

241242
To use your Google API key or Yahoo app ID:
@@ -247,6 +248,7 @@ To obtain an API key:
247248
* Yahoo: https://developer.apps.yahoo.com/wsregapp (not required)
248249
* Google: http://code.google.com/apis/maps/signup.html (not required)
249250
* Yandex: http://api.yandex.ru/maps/intro/concepts/intro.xml#apikey (required)
251+
* Bing: http://www.bingmapsportal.com/
250252

251253
=== Timeout
252254

lib/geocoder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def valid_lookups
8383
# All street address lookups, default first.
8484
#
8585
def street_lookups
86-
[:google, :yahoo, :geocoder_ca, :yandex]
86+
[:google, :yahoo, :bing, :geocoder_ca, :yandex]
8787
end
8888

8989
##

test/geocoder_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,23 @@ def test_freegeoip_result_components
403403
end
404404

405405

406+
# --- Bing ---
407+
408+
def test_bing_result_components
409+
Geocoder::Configuration.lookup = :bing
410+
result = Geocoder.search("Madison Square Garden, New York, NY").first
411+
assert_equal "Madison Square Garden, NY", result.address
412+
assert_equal "NY", result.state
413+
assert_equal "New York", result.city
414+
end
415+
416+
def test_bing_no_results
417+
Geocoder::Configuration.lookup = :bing
418+
results = Geocoder.search("no results")
419+
assert_equal 0, results.length
420+
end
421+
422+
406423
# --- search queries ---
407424

408425
def test_hash_to_query

test/test_helper.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ def fetch_raw_data(query, reverse = false)
119119
read_fixture "freegeoip_74_200_247_59.json"
120120
end
121121
end
122+
123+
class Bing < Base
124+
private #-----------------------------------------------------------------
125+
def fetch_raw_data(query, reverse = false)
126+
raise TimeoutError if query == "timeout"
127+
if reverse
128+
read_fixture "bing_reverse.json"
129+
else
130+
file = case query
131+
when "no results"; :no_results
132+
else :madison_square_garden
133+
end
134+
read_fixture "bing_#{file}.json"
135+
end
136+
end
137+
end
138+
122139
end
123140
end
124141

0 commit comments

Comments
 (0)