- query = params[:query]
- results = Array.new
-
- if query.match(/^\d{5}(-\d{4})?$/)
- results.push search_us_postcode(query)
- elsif query.match(/(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})/i)
- results.push search_uk_postcode(query)
- results.push search_osm_namefinder(query)
- elsif query.match(/[A-Z]\d[A-Z]\s*\d[A-Z]\d/i)
- results.push search_ca_postcode(query)
- else
- results.push search_osm_namefinder(query)
- results.push search_geonames(query)
- end
-
- results_count = count_results(results)
-
- render :update do |page|
- page.replace_html :sidebar_content, :partial => 'results', :object => results
-
- if results_count == 1
- position = results.collect { |s| s[:results] }.compact.flatten[0]
- page.call "setPosition", position[:lat], position[:lon], position[:zoom]
+ normalize_params
+
+ @sources = []
+
+ if params[:lat] && params[:lon]
+ @sources.push "latlon"
+ @sources.push "osm_nominatim_reverse"
+ @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME)
+ elsif params[:query]
+ if params[:query] =~ /^\d{5}(-\d{4})?$/
+ @sources.push "us_postcode"
+ @sources.push "osm_nominatim"
+ elsif params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
+ @sources.push "uk_postcode"
+ @sources.push "osm_nominatim"
+ elsif params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
+ @sources.push "ca_postcode"
+ @sources.push "osm_nominatim"