Created
March 5, 2018 23:10
-
-
Save rosem/47c05a2d6c024567ce67d187e7ab48b2 to your computer and use it in GitHub Desktop.
Updated
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 | |
# 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