Skip to content
Snippets Groups Projects
Commit f9eede12 authored by Alex Reisner's avatar Alex Reisner Committed by GitHub
Browse files

Merge pull request #1093 from bolandrm/rmb/geocodio_canada

support canada for geocodio
parents 1f92c262 2744939d
No related branches found
No related tags found
No related merge requests found
......@@ -24,16 +24,24 @@ module Geocoder::Result
alias_method :state_code, :state
def zip
address_components["zip"]
# Postal code is not returned for Canada geocode results
address_components["zip"] || ""
end
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']
end
def city
......
{"input":{"address_components":{"number":"1101","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania Ave NW","city":"Washington","state":"DC"},"formatted_address":"1101 Pennsylvania Ave NW, Washington, DC"},"results":[{"address_components":{"number":"1101","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania Ave NW","city":"Washington","county":"District of Columbia","state":"DC","zip":"20004"},"formatted_address":"1101 Pennsylvania Ave NW, Washington, DC 20004","location":{"lat":38.895019,"lng":-77.028095},"accuracy":1,"accuracy_type":"range_interpolation"},{"address_components":{"number":"1101","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania Ave NW","city":"Washington","county":"District of Columbia","state":"DC","zip":"20004"},"formatted_address":"1101 Pennsylvania Ave NW, Washington, DC 20004","location":{"lat":38.895016122449,"lng":-77.028084377551},"accuracy":0.8,"accuracy_type":"range_interpolation"}]}
\ No newline at end of file
{"input":{"address_components":{"number":"1101","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania Ave NW","city":"Washington","state":"DC","zip":"20001","country":"US"},"formatted_address":"1101 Pennsylvania Ave NW, Washington, DC 20001"},"results":[{"address_components":{"number":"1101","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania Ave NW","city":"Washington","county":"District of Columbia","state":"DC","zip":"20004","country":"US"},"formatted_address":"1101 Pennsylvania Ave NW, Washington, DC 20004","location":{"lat":38.895156,"lng":-77.027405},"accuracy":1,"accuracy_type":"rooftop","source":"DC Geographic Information Systems Program (DC GIS)"}]}
{"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,8 +18,22 @@ 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)
assert_equal({ "lat" => 38.895156, "lng" => -77.027405 }, 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
......
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