From: Tom Hughes Date: Sun, 7 Jul 2024 10:58:18 +0000 (+0100) Subject: Preserve lat and lon values as entered for reverse searches X-Git-Tag: live~445^2~3 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f047f86c1d4add3b6cd8074ccaa9b940fa2d0fd8 Preserve lat and lon values as entered for reverse searches --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8ec0ab6b7..0e0a2d8af 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -35,15 +35,15 @@ class GeocoderController < ApplicationController @results = [] if lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180 - @results.push(:lat => lat, :lon => lon, + @results.push(:lat => params[:lat], :lon => params[:lon], :zoom => params[:zoom], - :name => "#{lat}, #{lon}") + :name => "#{params[:lat]}, #{params[:lon]}") end if lon >= -90 && lon <= 90 && lat >= -180 && lat <= 180 - @results.push(:lat => lon, :lon => lat, + @results.push(:lat => params[:lon], :lon => params[:lat], :zoom => params[:zoom], - :name => "#{lon}, #{lat}") + :name => "#{params[:lon]}, #{params[:lat]}") end if @results.empty? @@ -61,9 +61,9 @@ class GeocoderController < ApplicationController @error = "Longitude #{lon} out of range" render :action => "error" else - @results = [{ :lat => lat, :lon => lon, + @results = [{ :lat => params[:lat], :lon => params[:lon], :zoom => params[:zoom], - :name => "#{lat}, #{lon}" }] + :name => "#{params[:lat]}, #{params[:lon]}" }] render :action => "results" end @@ -219,7 +219,7 @@ class GeocoderController < ApplicationController params.merge!(dms_to_decdeg(latlon)).delete(:query) elsif latlon = query.match(%r{^([+-]?\d+(\.\d*)?)(?:\s+|\s*[,/]\s*)([+-]?\d+(\.\d*)?)$}) - params.merge!(:lat => latlon[1].to_f, :lon => latlon[3].to_f).delete(:query) + params.merge!(:lat => latlon[1], :lon => latlon[3]).delete(:query) params[:latlon_digits] = true end diff --git a/test/controllers/geocoder_controller_test.rb b/test/controllers/geocoder_controller_test.rb index d32521c3b..15d4eb5f9 100644 --- a/test/controllers/geocoder_controller_test.rb +++ b/test/controllers/geocoder_controller_test.rb @@ -368,8 +368,8 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest assert_template :layout => "map" assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources).pluck(:name) assert_nil @controller.params[:query] - assert_in_delta lat, @controller.params[:lat] - assert_in_delta lon, @controller.params[:lon] + assert_in_delta lat, @controller.params[:lat].to_f + assert_in_delta lon, @controller.params[:lon].to_f get search_path(:query => query), :xhr => true assert_response :success @@ -377,8 +377,8 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest assert_template :layout => "xhr" assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources).pluck(:name) assert_nil @controller.params[:query] - assert_in_delta lat, @controller.params[:lat] - assert_in_delta lon, @controller.params[:lon] + assert_in_delta lat, @controller.params[:lat].to_f + assert_in_delta lon, @controller.params[:lon].to_f end def search_check(query, sources)