- if lat < -90 || lat > 90
- @error = "Latitude #{lat} out of range"
- render :action => "error"
- elsif lon < -180 || lon > 180
- @error = "Longitude #{lon} out of range"
- render :action => "error"
- else
- @results = [{ :lat => lat, :lon => lon,
- :zoom => params[:zoom],
- :name => "#{lat}, #{lon}" }]
-
- render :action => "results"
- end
- end
-
- def search_us_postcode
- # get query parameters
- query = params[:query]
-
- # create result array
- @results = []
-
- # ask geocoder.us (they have a non-commercial use api)
- response = fetch_text("http://rpc.geocoder.us/service/csv?zip=#{escape_query(query)}")
-
- # parse the response
- unless response =~ /couldn't find this zip/
- data = response.split(/\s*,\s+/) # lat,long,town,state,zip
- @results.push(:lat => data[0], :lon => data[1],
- :zoom => POSTCODE_ZOOM,
- :prefix => "#{data[2]}, #{data[3]},",
- :name => data[4])
- end
-
- render :action => "results"
- rescue StandardError => ex
- @error = "Error contacting rpc.geocoder.us: #{ex}"
- render :action => "error"
- end
-
- def search_uk_postcode
- # get query parameters
- query = params[:query]
-
- # create result array
- @results = []
-
- # ask npemap.org.uk to do a combined npemap + freethepostcode search
- response = fetch_text("http://www.npemap.org.uk/cgi/geocoder.fcgi?format=text&postcode=#{escape_query(query)}")