- if lat < -90 or lat > 90
- @error = "Latitude #{lat} out of range"
- render :action => "error"
- elsif lon < -180 or 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 = Array.new
-
- # 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.match(/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 Exception => ex
- @error = "Error contacting rpc.geocoder.us: #{ex.to_s}"
- render :action => "error"
- end
-
- def search_uk_postcode
- # get query parameters
- query = params[:query]
-
- # create result array
- @results = Array.new