Skip to content

Commit

Permalink
Add priority to neighbourhood component
Browse files Browse the repository at this point in the history
Some results return `neighbourhood` and/or `suburb`. Trying to maximize the results, we'll first try to get it from the `neighbourhood` component, and then, if it's empty, fallback with the `suburb` one.
  • Loading branch information
dsantosmerino committed Oct 15, 2019
1 parent 96b94bd commit efafa97
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/geokit/geocoders/opencage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def self.set_address_components(address_data, loc)
loc.zip = address_data['postcode']
loc.district = address_data['city_district']
loc.district = address_data['state_district'] if loc.district.nil? && address_data['state_district']
loc.neighborhood = address_data['suburb']
loc.neighborhood = address_data['neighbourhood']
loc.neighborhood = address_data['suburb'] if loc.neighborhood.nil?
loc.street_address = "#{address_data['road']} #{address_data['house_number']}".strip if address_data['road']
loc.street_name = address_data['road']
loc.street_number = address_data['house_number']
Expand Down
2 changes: 1 addition & 1 deletion test/test_opencage_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_opencage_reverse2
assert_equal 'MK', res.country_code
assert_equal 'opencage', res.provider

assert_equal 'Бончејца', res.neighborhood
assert_equal 'Жабино Маало', res.neighborhood
assert_equal 'Prilep', res.city
assert_equal 'Pelagonia Region', res.state

Expand Down

0 comments on commit efafa97

Please sign in to comment.