X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5925039729d551ef6b0987ab0337d3c437cb53fe..c203edda20370bb1760a091356f334d342ccb25b:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 384f2c24c..da5245687 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -39,18 +39,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 +306,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)