]> git.openstreetmap.org Git - rails.git/commitdiff
Cope with the OSM NameFinder returning a result with no nearby places.
authorTom Hughes <tom@compton.nu>
Tue, 7 Aug 2007 17:29:27 +0000 (17:29 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 7 Aug 2007 17:29:27 +0000 (17:29 +0000)
app/controllers/geocoder_controller.rb

index 9349eaca4dfc96154a51f05f30d3c2014062e8e9..480dc5419b2b5cf9c4e17c0f5eb6c55408eb74df 100644 (file)
@@ -91,11 +91,16 @@ private
       place = named.elements["place/named"] || named.elements["nearestplaces/named"]
       type = named.attributes["info"].to_s.capitalize
       name = named.attributes["name"].to_s
-      distance = format_distance(place.attributes["approxdistance"].to_i)
-      direction = format_direction(place.attributes["direction"].to_i)
-      placename = place.attributes["name"].to_s
-      results.push({:lat => lat, :lon => lon, :zoom => zoom,
-                    :description => "#{type} #{name}, #{distance} #{direction} of #{placename}"})
+      if place
+        distance = format_distance(place.attributes["approxdistance"].to_i)
+        direction = format_direction(place.attributes["direction"].to_i)
+        placename = place.attributes["name"].to_s
+        results.push({:lat => lat, :lon => lon, :zoom => zoom,
+                      :description => "#{type} #{name}, #{distance} #{direction} of #{placename}"})
+      else
+        results.push({:lat => lat, :lon => lon, :zoom => zoom,
+                      :description => "#{type} #{name}"})
+      end
     end
 
     return { :source => "OpenStreetMap Namefinder", :url => "http://www.frankieandshadow.com/osm/", :results => results }