end
def describe_location(lat, lon, zoom = nil, language = nil)
- 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}"
-
- begin
- response = OSM::Timer.timeout(4) do
- REXML::Document.new(Net::HTTP.get(URI.parse(url)))
- end
- rescue Exception
- response = nil
- end
-
- if response and result = response.get_text("reversegeocode/result")
- result.to_s
- else
- "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}"
- end
+ Nominatim.describe_location(lat, lon, zoom, language)
end
end
def note_comment_notification(comment, recipient)
@locale = recipient.preferred_language_from(I18n.available_locales)
@noteurl = browse_note_url(comment.note, :host => SERVER_URL)
- @place = comment.note.nearby_place
- @comment =comment.body
+ @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, @locale)
+ @comment = comment.body
@owner = recipient == comment.note.author
@commenter = comment.author_name
<a href="<%= url_for :controller => 'site', :action => 'index', :lat => location.latitude, :lon => location.longitude, :zoom => 14 %>">
<abbr class="geo" title="<%= number_with_precision(location.latitude, :precision => 4) %>; <%= number_with_precision(location.longitude, :precision => 4) %>">
-<% cache(:controller => 'diary_entry', :action => 'view', :display_name => location.user.display_name, :id => location.id, :part => "location") do %>
<%= describe_location location.latitude, location.longitude, 14, location.language_code %>
-<% end %>
</abbr>
</a>
xml.item do
- location_string = Rails.cache.fetch("location_description_#{note.lat}_#{note.lon}_#{locale}") do
- describe_location note.lat, note.lon, 14, locale
- end
+ location = describe_location(note.lat, note.lon, 14, locale)
+
if note.status == "closed"
- xml.title t('note.rss.closed', :place => location_string)
+ xml.title t('note.rss.closed', :place => location)
elsif note.comments.length > 1
- xml.title t('note.rss.comment', :place => location_string)
+ xml.title t('note.rss.comment', :place => location)
else
- xml.title t('note.rss.new', :place => location_string)
+ xml.title t('note.rss.new', :place => location)
end
xml.link browse_note_url(note)
xml.link url_for(:controller => "site", :action => "index", :only_path => false)
@comments.each do |comment|
- location_string = Rails.cache.fetch("location_description_#{comment.note.lat}_#{comment.note.lon}_#{locale}") do
- describe_location comment.note.lat, comment.note.lon, 14, locale
- end
+ location = describe_location(comment.note.lat, comment.note.lon, 14, locale)
+
xml.item do
if comment.event == "closed"
- xml.title t('note.rss.closed', :place => location_string)
+ xml.title t('note.rss.closed', :place => location)
elsif comment.event == "commented"
- xml.title t('note.rss.comment', :place => location_string)
+ xml.title t('note.rss.comment', :place => location)
elsif comment.event == "opened"
- xml.title t('note.rss.new', :place => location_string)
+ xml.title t('note.rss.new', :place => location)
else
xml.title "unknown event"
end
--- /dev/null
+module Nominatim
+ def self.describe_location(lat, lon, zoom = nil, language = nil)
+ zoom = zoom || 14
+ language = language || request.user_preferred_languages.join(',')
+
+ Rails.cache.fetch "/nominatim/location/#{lat}/#{lon}/#{zoom}/#{language}" do
+ url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
+
+ begin
+ response = OSM::Timer.timeout(4) do
+ REXML::Document.new(Net::HTTP.get(URI.parse(url)))
+ end
+ rescue Exception
+ response = nil
+ end
+
+ if response and result = response.get_text("reversegeocode/result")
+ result.to_s
+ else
+ "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}"
+ end
+ end
+ end
+end