Skip to content
Snippets Groups Projects
Commit 19a8c8f2 authored by Alex Reisner's avatar Alex Reisner
Browse files

Always include distance and bearing columns.

This addresses issue #199 and is more directly a response to the
excellent comments from github.com/zetetic on commit 1b658304.
parent 14d350e1
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,10 @@ module Geocoder::Store
if Geocoder::Calculations.coordinates_present?(latitude, longitude)
near_scope_options(latitude, longitude, *args)
else
where(false_condition) # no results if no lat/lon given
# If no lat/lon given we don't want any results, but we still
# need distance and bearing columns so you can add, for example:
# .order("distance")
select(select_clause(nil, "NULL", "NULL")).where(false_condition)
end
}
......@@ -49,7 +52,9 @@ module Geocoder::Store
#
scope :within_bounding_box, lambda{ |bounds|
sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds
return where(false_condition) unless sw_lat && sw_lng && ne_lat && ne_lng
unless sw_lat && sw_lng && ne_lat && ne_lng
return select(select_clause(nil, "NULL", "NULL")).where(false_condition)
end
spans = "#{geocoder_options[:latitude]} BETWEEN #{sw_lat} AND #{ne_lat} AND "
spans << if sw_lng > ne_lng # Handle a box that spans 180
"#{geocoder_options[:longitude]} BETWEEN #{sw_lng} AND 180 OR " +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment