Skip to content

Instantly share code, notes, and snippets.

@rosem
Created March 5, 2018 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosem/47c05a2d6c024567ce67d187e7ab48b2 to your computer and use it in GitHub Desktop.
Save rosem/47c05a2d6c024567ce67d187e7ab48b2 to your computer and use it in GitHub Desktop.
Updated
def geolocated
address_point = origin = [params[:lat].to_f, params[:lng].to_f]
if params[:ne] && params[:sw]
sw_lat, sw_lng = params[:sw].split(/,/)
ne_lat, ne_lng = params[:ne].split(/,/)
bounds = Geokit::Bounds.new(Geokit::LatLng.new(sw_lat,sw_lng),Geokit::LatLng.new(ne_lat,ne_lng))
current_user.update_region(bounds)
# use the center of the search region for distance calculation
address_point = origin = bounds.center
# by_distance = geo_scope
@rooms = Room.in_bounds(bounds).where(["private = ?",false]).active.categorized(params[:category]).with_counters(current_user.id).by_distance(:origin => origin).order('featured DESC NULLS LAST').order('last_message_at DESC NULLS LAST').limit(50)
else
# by_distance = geo_scope.order('distance ASC')
@rooms = Room.where(["private = ?",false]).active.categorized(params[:category]).with_counters(current_user.id,true).by_distance(:origin => origin).order('featured DESC NULLS LAST').order('last_message_at DESC NULLS LAST').limit(10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment