Skip to content
Snippets Groups Projects
Commit 55cea457 authored by Ryan Boland's avatar Ryan Boland
Browse files

support canada for geocodio

parent 35115b4f
No related branches found
No related tags found
No related merge requests found
...@@ -29,11 +29,18 @@ module Geocoder::Result ...@@ -29,11 +29,18 @@ module Geocoder::Result
alias_method :postal_code, :zip alias_method :postal_code, :zip
def country 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 end
def country_code def country_code
"US" # Geocodio only supports the US address_components['country'] || "US"
end end
def city def city
......
{"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"}]}
...@@ -18,10 +18,24 @@ class GeocodioTest < GeocoderTestCase ...@@ -18,10 +18,24 @@ class GeocodioTest < GeocoderTestCase
assert_equal "20004", result.zip assert_equal "20004", result.zip
assert_equal "NW", result.postdirectional assert_equal "NW", result.postdirectional
assert_equal "Washington", result.city 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 "1101 Pennsylvania Ave NW, Washington, DC 20004", result.formatted_address
assert_equal({ "lat" => 38.895019, "lng" => -77.028095 }, result.location) assert_equal({ "lat" => 38.895019, "lng" => -77.028095 }, result.location)
end 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 def test_no_results
results = Geocoder.search("no results") results = Geocoder.search("no results")
assert_equal 0, results.length assert_equal 0, results.length
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment