4 extend ActionView::Helpers::NumberHelper
6 def self.describe_location(lat, lon, zoom = nil, language = nil)
8 language ||= http_accept_language.user_preferred_languages.join(",")
10 Rails.cache.fetch "/nominatim/location/#{lat}/#{lon}/#{zoom}/#{language}" do
11 url = "https://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
14 response = Timeout.timeout(4) do
15 REXML::Document.new(Net::HTTP.get(URI.parse(url)))
21 if response && result = response.get_text("reversegeocode/result")
24 "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}"