]> 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 d805e27adee83bfe8518ec846b943940e5fd7dbb..e466e83491e31126e26660ace99be2b6e7160a5a 100644 (file)
@@ -1,4 +1,6 @@
 module ApplicationHelper
+  require 'rexml/document'
+
   def htmlize(text)
     return linkify(sanitize(simple_format(text)))
   end
@@ -34,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)