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

Merge pull request #160 from kongo/within_bounding_box_fix

within_bounding_box scope takes field names from options
parents e9cd55cb e6f56621
No related branches found
No related tags found
No related merge requests found
......@@ -50,11 +50,11 @@ module Geocoder::Store
scope :within_bounding_box, lambda{ |bounds|
sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds
return where(:id => false) unless sw_lat && sw_lng && ne_lat && ne_lng
spans = "latitude BETWEEN #{sw_lat} AND #{ne_lat} AND "
spans = "#{geocoder_options[:latitude]} BETWEEN #{sw_lat} AND #{ne_lat} AND "
spans << if sw_lng > ne_lng # Handle a box that spans 180
"longitude BETWEEN #{sw_lng} AND 180 OR longitude BETWEEN -180 AND #{ne_lng}"
"#{geocoder_options[:longitude]} BETWEEN #{sw_lng} AND 180 OR #{geocoder_options[:longitude]} BETWEEN -180 AND #{ne_lng}"
else
"longitude BETWEEN #{sw_lng} AND #{ne_lng}"
"#{geocoder_options[:longitude]} BETWEEN #{sw_lng} AND #{ne_lng}"
end
{ :conditions => spans }
}
......
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