Skip to content

Commit

Permalink
Merge pull request alexreisner#160 from kongo/within_bounding_box_fix
Browse files Browse the repository at this point in the history
within_bounding_box scope takes field names from options
  • Loading branch information
alexreisner committed Jan 14, 2012
2 parents e9cd55c + e6f5662 commit da7db55
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/geocoder/stores/active_record.rb
Expand Up @@ -50,11 +50,11 @@ def self.included(base)
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 }
}
Expand Down

0 comments on commit da7db55

Please sign in to comment.