- # 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
-
- # 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)}")
-
- # parse the response
- unless response.match(/Error/)
- dataline = response.split(/\n/)[1]
- data = dataline.split(/,/) # easting,northing,postcode,lat,long
- postcode = data[2].gsub(/'/, "")
- zoom = POSTCODE_ZOOM - postcode.count("#")
- @results.push({:lat => data[3], :lon => data[4], :zoom => zoom,
- :name => postcode})
- end
-
- render :action => "results"
- rescue Exception => ex
- @error = "Error contacting www.npemap.org.uk: #{ex.to_s}"
- render :action => "error"
- end
-
- def search_ca_postcode
- # get query parameters
- query = params[:query]
- @results = Array.new
+ if lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180
+ @results.push(:lat => params[:lat], :lon => params[:lon],
+ :zoom => params[:zoom],
+ :name => "#{params[:lat]}, #{params[:lon]}")
+ end