- @error = "Error contacting nominatim.openstreetmap.org: #{e}"
- render :action => "error"
- end
-
- def search_geonames
- # get query parameters
- query = params[:query]
-
- # get preferred language
- lang = I18n.locale.to_s.split("-").first
-
- # create result array
- @results = []
-
- # ask geonames.org
- response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{Settings.geonames_username}")
-
- # parse the response
- response.elements.each("geonames/geoname") do |geoname|
- lat = geoname.text("lat")
- lon = geoname.text("lng")
- name = geoname.text("name")
- country = geoname.text("countryName")
-
- @results.push(:lat => lat, :lon => lon,
- :zoom => Settings.geonames_zoom,
- :name => name,
- :suffix => ", #{country}")
- end
-
- render :action => "results"
- rescue StandardError => e
- @error = "Error contacting api.geonames.org: #{e}"