X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a20e28809f5ca1e3f3579faeaf118fff3ecc4994..11806a676fb88f51ece004b7c05bde38f1e77706:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 384f2c24c..b9cf8d096 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -6,6 +6,7 @@ class GeocoderController < ApplicationController before_action :authorize_web before_action :set_locale before_action :require_oauth, :only => [:search] + authorize_resource :class => false def search @params = normalize_params @@ -39,18 +40,44 @@ class GeocoderController < ApplicationController def search_latlon lat = params[:lat].to_f lon = params[:lon].to_f - if lat < -90 || lat > 90 - @error = "Latitude #{lat} out of range" - render :action => "error" - elsif lon < -180 || lon > 180 - @error = "Longitude #{lon} out of range" - render :action => "error" + + if params[:latlon_digits] + # We've got two nondescript numbers for a query, which can mean both "lat, lon" or "lon, lat". + @results = [] + + if lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180 + @results.push(:lat => lat, :lon => lon, + :zoom => params[:zoom], + :name => "#{lat}, #{lon}") + end + + if lon >= -90 && lon <= 90 && lat >= -180 && lat <= 180 + @results.push(:lat => lon, :lon => lat, + :zoom => params[:zoom], + :name => "#{lon}, #{lat}") + end + + if @results.empty? + @error = "Latitude or longitude are out of range" + render :action => "error" + else + render :action => "results" + end else - @results = [{ :lat => lat, :lon => lon, - :zoom => params[:zoom], - :name => "#{lat}, #{lon}" }] + # Coordinates in a query have come with markers for latitude and longitude. + if lat < -90 || lat > 90 + @error = "Latitude #{lat} out of range" + render :action => "error" + elsif lon < -180 || 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" + render :action => "results" + end end end @@ -280,10 +307,12 @@ class GeocoderController < ApplicationController elsif latlon = query.match(/^\s*([+-]?\d+(\.\d*)?)\s*[\s,]\s*([+-]?\d+(\.\d*)?)\s*$/) params.merge!(:lat => latlon[1].to_f, :lon => latlon[3].to_f).delete(:query) + + params[:latlon_digits] = true unless params[:whereami] end end - params.permit(:query, :lat, :lon, :zoom, :minlat, :minlon, :maxlat, :maxlon) + params.permit(:query, :lat, :lon, :latlon_digits, :zoom, :minlat, :minlon, :maxlat, :maxlon) end def nsew_to_decdeg(captures)