]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/application_helper.rb
Use Nominatim to reverse geocode diary location information and display
[rails.git] / app / helpers / application_helper.rb
index 2eebec1708378663a5bc4f67ad828ec5dd847da9..e466e83491e31126e26660ace99be2b6e7160a5a 100644 (file)
@@ -1,6 +1,12 @@
 module ApplicationHelper
+  require 'rexml/document'
+
   def htmlize(text)
-    return sanitize(auto_link(simple_format(text), :link => :urls, :html => { :rel => "nofollow" }))
+    return linkify(sanitize(simple_format(text)))
+  end
+
+  def linkify(text)
+    return auto_link(text, :link => :urls, :html => { :rel => "nofollow" })
   end
 
   def html_escape_unicode(text)
@@ -30,6 +36,15 @@ module ApplicationHelper
     return js
   end
 
+  def describe_location(lat, lon, zoom, language)
+    zoom = zoom || 14
+    language = language || request.user_preferred_languages.join(',')
+    url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
+    response = REXML::Document.new(Net::HTTP.get(URI.parse(url)))
+
+    return response.get_text("reversegeocode/result").to_s
+  end
+
 private
 
   def javascript_strings_for_key(key)