diff --git a/lib/geocoder/results/geocodio.rb b/lib/geocoder/results/geocodio.rb index b240b1750fc6d9058b6e8c17f2df007366c8a9ed..dbe5605f8b247778eab6813408d874698f569b53 100644 --- a/lib/geocoder/results/geocodio.rb +++ b/lib/geocoder/results/geocodio.rb @@ -29,11 +29,18 @@ module Geocoder::Result alias_method :postal_code, :zip def country - "United States" # Geocodio only supports the US + # Geocodio supports US and Canada, however they don't return the full + # country name. + + if country_code == "CA" + "Canada" + else + "United States" + end end def country_code - "US" # Geocodio only supports the US + address_components['country'] || "US" end def city diff --git a/test/fixtures/geocodio_reverse b/test/fixtures/geocodio_reverse new file mode 100644 index 0000000000000000000000000000000000000000..9930dfab2725ac76ffc8497690cce532004dc7fe --- /dev/null +++ b/test/fixtures/geocodio_reverse @@ -0,0 +1 @@ +{"results":[{"address_components":{"number":"483","street":"Bay","suffix":"St","formatted_street":"Bay St","city":"Toronto","state":"ON","country":"CA"},"formatted_address":"483 Bay St, Toronto, ON","location":{"lat":43.652961,"lng":-79.382624},"accuracy":1,"accuracy_type":"nearest_street","source":"CanVec+ by Natural Resources Canada"},{"address_components":{"number":"20","street":"Albert","suffix":"St","formatted_street":"Albert St","city":"Toronto","state":"ON","country":"CA"},"formatted_address":"20 Albert St, Toronto, ON","location":{"lat":43.652961,"lng":-79.382624},"accuracy":0.16,"accuracy_type":"nearest_street","source":"CanVec+ by Natural Resources Canada"}]} diff --git a/test/unit/lookups/geocodio_test.rb b/test/unit/lookups/geocodio_test.rb index 6b316be9825d9e726e87d9f7f9dd28664bb50082..250ce410f220d662f74ce75f6bc3107937b3430e 100644 --- a/test/unit/lookups/geocodio_test.rb +++ b/test/unit/lookups/geocodio_test.rb @@ -18,10 +18,24 @@ class GeocodioTest < GeocoderTestCase assert_equal "20004", result.zip assert_equal "NW", result.postdirectional assert_equal "Washington", result.city + assert_equal "US", result.country_code + assert_equal "United States", result.country assert_equal "1101 Pennsylvania Ave NW, Washington, DC 20004", result.formatted_address assert_equal({ "lat" => 38.895019, "lng" => -77.028095 }, result.location) end + def test_reverse_canada_result + result = Geocoder.search([43.652961, -79.382624]).first + assert_equal 1.0, result.accuracy + assert_equal "483", result.number + assert_equal "Bay", result.street + assert_equal "St", result.suffix + assert_equal "ON", result.state + assert_equal "Toronto", result.city + assert_equal "CA", result.country_code + assert_equal "Canada", result.country + end + def test_no_results results = Geocoder.search("no results") assert_equal 0, results.length