Created
March 5, 2018 23:10
-
-
Save rosem/627488256595ce20be797db0085570a9 to your computer and use it in GitHub Desktop.
Original
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
@rooms = Room.in_bounds(bounds).where(["private = ?",false]).active.categorized(params[:category]).with_counters(current_user.id).geo_scope(:origin => origin).order('featured DESC NULLS LAST').order('last_message_at DESC NULLS LAST').limit(50) | |
else | |
@rooms = Room.where(["private = ?",false]).active.categorized(params[:category]).with_counters(current_user.id,true).geo_scope(:origin => origin).order('distance ASC').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