正如这里所讨论的(问题:我们还可以在地图上显示哪些数据层? )我实现了(#3719)一种新方法,可以根据给定的纬度、经度和标签(可选)搜索附近的人。
代码在这里: https :
def tagNearbyPeople(query, tag, limit = 10)
raise("Must separate coordinates with ,") unless query.include? ","
lat, lon = query.split(',')
user_locations = User.where('rusers.status <> 0')\
.joins(:user_tags)\
.where('value LIKE ?', 'lat:' + lat[0..lat.length - 2] + '%')\
.distinct
if tag.present?
user_locations = User.joins(:user_tags)\
.where('user_tags.value LIKE ?', tag)\
.where(id: user_locations.select("rusers.id"))
end
ids = user_locations.collect(&:id).uniq || []
items = User.where('rusers.status <> 0').joins(:user_tags)
.where('rusers.id IN (?) AND value LIKE ?', ids, 'lon:' + lon[0..lon.length - 2] + '%')
# selects the items whose node_tags don't have the location:blurred tag
items.select do |item|
item.user_tags.none? do |user_tag|
user_tag.name == "location:blurred"
end
end
items = items.limit(limit)
end
现在,作为下一步,我们需要修改方法以至少按最近的注册对结果进行排序。
search_profiles()
方法按最近用户对结果进行排序,我认为这里可以使用相同的策略。
惊人的 !!!
@milaaraujo我可以解决这个问题吗?
当然,只需将问题分配给自己!