Browse Source

Improved city searching

development
Godwin 8 years ago
committed by GitHub
parent
commit
868f21a5f7
  1. 7
      app/models/city.rb

7
app/models/city.rb

@ -19,7 +19,8 @@ class City < ActiveRecord::Base
location = Geocoder.search(address, language: locale.to_s).first location = Geocoder.search(address, language: locale.to_s).first
location.data['address_components'].each do | component | location.data['address_components'].each do | component |
if component['types'].first == 'locality' # city is usually labelled a 'locality' but sometimes this is missing and only 'colloquial_area' is present
if component['types'].first == 'locality' || component['types'].first == 'colloquial_area'
return component['short_name'] return component['short_name']
end end
end end
@ -29,8 +30,11 @@ class City < ActiveRecord::Base
def translate_city(locale) def translate_city(locale)
translation = get_translation(locale) translation = get_translation(locale)
if translation.present?
set_column_for_locale(:city, locale, translation) set_column_for_locale(:city, locale, translation)
save! save!
end
return translation return translation
end end
@ -53,6 +57,7 @@ class City < ActiveRecord::Base
# otherwise build a new city # otherwise build a new city
component_alises = { component_alises = {
'locality' => :city, 'locality' => :city,
'colloquial_area' => :city,
'administrative_area_level_1' => :territory, 'administrative_area_level_1' => :territory,
'country' => :country 'country' => :country
} }

Loading…
Cancel
Save