diff --git a/README.rdoc b/README.rdoc index 4c50d8822ec4d1dd40bbe1403d341afe3218ef2f..469662e842c603ccc2f02b4764afd078787ee525 100644 --- a/README.rdoc +++ b/README.rdoc @@ -227,6 +227,7 @@ Street address geocoding services currently supported (valid settings for the ab * Google: <tt>:google</tt> * Yahoo: <tt>:yahoo</tt> * Geocoder.ca: <tt>:geocoder_ca</tt> (US and Canada only) +* Bing: <tt>:bing</tt> 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: @@ -235,7 +236,7 @@ Note that the result objects returned by different geocoding services all implem * Geocoder.ca: (???) * Yandex: http://api.yandex.ru/maps/geocoder/doc/desc/concepts/response_structure.xml * FreeGeoIP: http://github.com/fiorix/freegeoip/blob/master/README.rst - +* Bing: http://msdn.microsoft.com/en-us/library/ff701715.aspx === API Keys To use your Google API key or Yahoo app ID: @@ -247,6 +248,7 @@ To obtain an API key: * Yahoo: https://developer.apps.yahoo.com/wsregapp (not required) * Google: http://code.google.com/apis/maps/signup.html (not required) * Yandex: http://api.yandex.ru/maps/intro/concepts/intro.xml#apikey (required) +* Bing: http://www.bingmapsportal.com/ === Timeout diff --git a/lib/geocoder.rb b/lib/geocoder.rb index daf717d5afd50e8454404d2ac4c5472636149606..8b9bab2e5d514c35a5d21f7fe444f4d1204be5fe 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -83,7 +83,7 @@ module Geocoder # All street address lookups, default first. # def street_lookups - [:google, :yahoo, :geocoder_ca, :yandex] + [:google, :yahoo, :bing, :geocoder_ca, :yandex] end ## diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 752a4ec9d05b45c12df3cfaac06cbf244f5b73aa..b86b7db4f482572eca0f866ebe891c473449aa3d 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -403,6 +403,23 @@ class GeocoderTest < Test::Unit::TestCase end + # --- Bing --- + + def test_bing_result_components + Geocoder::Configuration.lookup = :bing + result = Geocoder.search("Madison Square Garden, New York, NY").first + assert_equal "Madison Square Garden, NY", result.address + assert_equal "NY", result.state + assert_equal "New York", result.city + end + + def test_bing_no_results + Geocoder::Configuration.lookup = :bing + results = Geocoder.search("no results") + assert_equal 0, results.length + end + + # --- search queries --- def test_hash_to_query diff --git a/test/test_helper.rb b/test/test_helper.rb index 958fad52f4b44f275cf9e746ddedfd5b6102f4b0..d9a1463a876d7ff240c628863717e645e24712c5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -119,6 +119,23 @@ module Geocoder read_fixture "freegeoip_74_200_247_59.json" end end + + class Bing < Base + private #----------------------------------------------------------------- + def fetch_raw_data(query, reverse = false) + raise TimeoutError if query == "timeout" + if reverse + read_fixture "bing_reverse.json" + else + file = case query + when "no results"; :no_results + else :madison_square_garden + end + read_fixture "bing_#{file}.json" + end + end + end + end end