+ def results
+ @place_name = params[:place_name]
+ res_hash = {}
+ @res_ary = []
+ begin
+ Net::HTTP.start('ws.geonames.org') do |http|
+ res = http.get("/search?q=#{URI.escape(@place_name)}&maxRows=10")
+ xml = REXML::Document.new(res.body)
+ xml.elements.each("geonames/geoname") do |ele|
+ res_hash = {}
+ ele.elements.each("name"){ |n| res_hash['name'] = n.text }
+ ele.elements.each("countryCode"){ |n| res_hash['countrycode'] = n.text }
+ ele.elements.each("countryName"){ |n| res_hash['countryname'] = n.text }
+ ele.elements.each("lat"){ |n| res_hash['lat'] = n.text }
+ ele.elements.each("lng"){ |n| res_hash['lon']= n.text }
+ @res_ary << res_hash
+ end
+ end
+
+ flash.delete(:notice)
+ rescue Timeout::Error
+ flash[:notice] = "Timed out waiting for results from ws.geonames.org"
+ rescue Exception => ex
+ flash[:notice] = "Error contacting ws.geonames.org: #{ex.to_s}"
+ end