1 class GeocoderController < ApplicationController
4 require 'rexml/document'
10 =begin if params[:geocode][:place]
11 postcode = params[:geocode][:place]
12 Net::HTTP.start('ws.geonames.org') do |http|
13 res = http.get("/search?q=#{query}&maxRows=10")
14 xml = REXML::Document.new(res.body)
15 xml.elements.each("/geonames/geoname") do |ele|
16 ele.elements.each("name"){ |n| @res_hash['name'] = n.text }
17 ele.elements.each("countryCode"){ |n| @res_hash['country'] = n.text }
18 ele.elements.each("lat"){ |n| @res_hash['lat'] = n.text }
19 ele.elements.each("lng"){ |n| @res_hash['lon']= n.text }
25 if params[:query][:postcode]
26 postcode = params[:query][:postcode]
27 Net::HTTP.start('www.freethepostcode.org') do |http|
28 resp = http.get("/geocode?postcode=#{postcode}")
29 lat = resp.body.scan(/[4-6][0-9]\.?[0-9]+/)
30 lon = resp.body.scan(/[-+][0-9]\.?[0-9]+/)
31 @postcode_array = [lat, lon]
33 redirect_to "/index.html?lat=#{@postcode_array[0]}&lon=#{@postcode_array[1]}&zoom=14"