]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/geocoder_controller.rb
Make sure all pages using the map layout call require_oauth
[rails.git] / app / controllers / geocoder_controller.rb
index ac6a2013ccdb62a926a6f85d4f5d023014cffbaf..87eb329abfe9fc998c271af4ad1b328ae807bfd6 100644 (file)
@@ -13,6 +13,7 @@ class GeocoderController < ApplicationController
 
     @sources = []
     if params[:lat] && params[:lon]
+      @sources.push "latlon"
       @sources.push "osm_nominatim_reverse"
       @sources.push "geonames_reverse"
     elsif params[:query].match(/^\d{5}(-\d{4})?$/)
@@ -28,6 +29,26 @@ class GeocoderController < ApplicationController
       @sources.push "osm_nominatim"
       @sources.push "geonames" if defined?(GEONAMES_USERNAME)
     end
+
+    render :layout => map_layout
+  end
+
+  def search_latlon
+    lat = params[:lat].to_f
+    lon = params[:lon].to_f
+    if lat < -90 or lat > 90
+      @error = "Latitude #{lat} out of range"
+      render :action => "error"
+    elsif lon < -180 or lon > 180
+      @error = "Longitude #{lon} out of range"
+      render :action => "error"
+    else
+      @results = [{:lat => lat, :lon => lon,
+                   :zoom => params[:zoom],
+                   :name => "#{lat}, #{lon}"}]
+
+      render :action => "results"
+    end
   end
 
   def search_us_postcode
@@ -141,7 +162,11 @@ class GeocoderController < ApplicationController
       type = place.attributes["type"].to_s
       name = place.attributes["display_name"].to_s
       min_lat,max_lat,min_lon,max_lon = place.attributes["boundingbox"].to_s.split(",")
-      prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize
+      if type.empty?
+        prefix_name = ""
+      else
+        prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize
+      end
       if klass == 'boundary' and type == 'administrative'
         rank = (place.attributes["place_rank"].to_i + 1) / 2
         prefix_name = t "geocoder.search_osm_nominatim.admin_levels.level#{rank}", :default => prefix_name