+ prefix = t ".prefix_format", :name => prefix_name
+ object_type = place.attributes["osm_type"]
+ object_id = place.attributes["osm_id"]
+
+ @results.push(:lat => lat, :lon => lon,
+ :min_lat => min_lat, :max_lat => max_lat,
+ :min_lon => min_lon, :max_lon => max_lon,
+ :prefix => prefix, :name => name,
+ :type => object_type, :id => object_id)
+ end
+
+ render :action => "results"
+ rescue StandardError => e
+ host = URI(Settings.nominatim_url).host
+ @error = "Error contacting #{host}: #{e}"
+ render :action => "error"
+ end
+
+ def search_osm_nominatim_reverse
+ # get query parameters
+ zoom = params[:zoom]
+
+ # create result array
+ @results = []
+
+ # ask nominatim
+ response = fetch_xml(nominatim_reverse_url(:format => "xml"))
+
+ # parse the response
+ response.elements.each("reversegeocode/result") do |result|
+ lat = result.attributes["lat"]
+ lon = result.attributes["lon"]
+ object_type = result.attributes["osm_type"]
+ object_id = result.attributes["osm_id"]
+ description = result.text
+
+ @results.push(:lat => lat, :lon => lon,
+ :zoom => zoom,
+ :name => description,
+ :type => object_type, :id => object_id)
+ end
+
+ render :action => "results"
+ rescue StandardError => e
+ host = URI(Settings.nominatim_url).host
+ @error = "Error contacting #{host}: #{e}"
+ render :action => "error"
+ end
+
+ private
+
+ def nominatim_url(format: nil)
+ # get query parameters
+ query = params[:query]
+ minlon = params[:minlon]
+ minlat = params[:minlat]
+ maxlon = params[:maxlon]
+ maxlat = params[:maxlat]
+
+ # get view box
+ viewbox = "&viewbox=#{minlon},#{maxlat},#{maxlon},#{minlat}" if minlon && minlat && maxlon && maxlat
+
+ # get objects to excude
+ exclude = "&exclude_place_ids=#{params[:exclude]}" if params[:exclude]
+
+ # build url
+ "#{Settings.nominatim_url}search?format=#{format}&extratags=1&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}"
+ end
+
+ def nominatim_reverse_url(format: nil)
+ # get query parameters
+ lat = params[:lat]
+ lon = params[:lon]
+ zoom = params[:zoom]
+
+ # build url
+ "#{Settings.nominatim_url}reverse?format=#{format}&lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}"
+ end
+
+ def fetch_text(url)
+ response = OSM.http_client.get(URI.parse(url))
+
+ if response.success?
+ response.body