- 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 => APP_CONFIG['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 = APP_CONFIG['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
-
- # ask geocoder.ca (note - they have a per-day limit)
- response = fetch_xml("http://geocoder.ca/?geoit=XML&postal=#{escape_query(query)}")
-
- # parse the response
- if response.get_elements("geodata/error").empty?
- @results.push({:lat => response.get_text("geodata/latt").to_s,
- :lon => response.get_text("geodata/longt").to_s,
- :zoom => APP_CONFIG['postcode_zoom'],
- :name => query.upcase})
- end
-
- render :action => "results"
- rescue Exception => ex
- @error = "Error contacting geocoder.ca: #{ex.to_s}"
- render :action => "error"
- end
-
- def search_osm_namefinder
- # get query parameters
- query = params[:query]