diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb index 805ee6a4d051783b84d8938183ee0201897fc3d1..7fd47a5a5377837ecb5c14be0334e89b39ed7560 100644 --- a/lib/geocoder/stores/active_record.rb +++ b/lib/geocoder/stores/active_record.rb @@ -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 " +