X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a4f4714d0e1b1eeabe5e4b411800b949ef1e1139..40c7e0f9aa2fc0d1353818e5316da2203d114cf0:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8f0f80441..b352c315b 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -5,12 +5,34 @@ class GeocoderController < ApplicationController require 'rexml/document' def search - @postcode_arr = [] - unless params[:query][:postcode].empty? - postcode = params[:query][:postcode].upcase - escaped_postcode = postcode.sub(/\s/,'%20') + if params[:postcode] + unless params[:postcode].empty? + postcode = params[:postcode] + check_postcode(postcode) + return + end + end + if params[:query][:postcode] + unless params[:query][:postcode].empty? + postcode =params[:query][:postcode] + check_postcode(postcode) + return + end + end + if params[:query][:place_name] + @place_name = params[:query][:place_name] + redirect_to :controller => 'geocoder', :action => 'results', :params => {:place_name => @place_name} + end + end + + def check_postcode(p) + + @postcode_arr = [] + postcode = p.upcase + escaped_postcode = postcode.sub(/\s/,'%20') + begin if postcode.match(/(^\d{5}$)|(^\d{5}-\d{4}$)/) # Its a zip code - ask geocoder.us # (They have a non commerical use api) @@ -90,12 +112,10 @@ class GeocoderController < ApplicationController redirect_to "/index.html?error=unknown_postcode_or_zip" return end + rescue + #Its likely that an api is down + redirect_to "/index.html?error=api_dpwn" end - - if params[:query][:place_name] - @place_name = params[:query][:place_name] - redirect_to :controller => 'geocoder', :action => 'results', :params => {:place_name => @place_name} - end end def results