- results.push({:lat => lat, :lon => lon, :zoom => 12,
- :name => name,
- :suffix => ", #{country}"})
+ @results.push({:lat => lat, :lon => lon,
+ :zoom => GEONAMES_ZOOM,
+ :name => name,
+ :suffix => ", #{country}"})
+ end
+
+ render :action => "results"
+ rescue Exception => ex
+ @error = "Error contacting ws.geonames.org: #{ex.to_s}"
+ render :action => "error"
+ end
+
+ def description
+ @sources = Array.new
+
+ @sources.push({ :name => "osm_nominatim" })
+ @sources.push({ :name => "geonames" })
+ end
+
+ def description_osm_nominatim
+ # get query parameters
+ lat = params[:lat]
+ lon = params[:lon]
+ zoom = params[:zoom]
+
+ # create result array
+ @results = Array.new
+
+ # ask nominatim
+ response = fetch_xml("#{NOMINATIM_URL}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{request.user_preferred_languages.join(',')}")
+
+ # parse the response
+ response.elements.each("reversegeocode/result") do |result|
+ description = result.get_text.to_s
+
+ @results.push({:prefix => "#{description}"})
+ end
+
+ render :action => "results"
+ rescue Exception => ex
+ @error = "Error contacting nominatim.openstreetmap.org: #{ex.to_s}"
+ render :action => "error"
+ end
+
+ def description_geonames
+ # get query parameters
+ lat = params[:lat]
+ lon = params[:lon]
+
+ # create result array
+ @results = Array.new
+
+ # ask geonames.org
+ response = fetch_xml("http://ws.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}")
+
+ # parse the response
+ response.elements.each("geonames/countrySubdivision") do |geoname|
+ name = geoname.get_text("adminName1").to_s
+ country = geoname.get_text("countryName").to_s
+ @results.push({:prefix => "#{name}, #{country}"})