module Geocoder::Sql
def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr)
def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr) spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND " # handle box that spans 180 longitude if sw_lng.to_f > ne_lng.to_f spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " + "#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})" else spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}" end end