我在尝试根据与用户的接近程度显示某些位置时遇到一个小问题。在我的 Controller 中我有这个:
if User.find(current_user)
@user = User.find(current_user)
@locations = Location.near(params[:latitude => @user.latitude, :longitude => @user.longitude], 50, :order => :distance)
end
用户存储了纬度和经度。我想我在 Location.near 行中没有得到正确的参数,但我不知道它们应该是什么。
如有任何帮助,我们将不胜感激。
干杯!
最佳答案
让我们稍微重写一下,current_user 应该已经设置好了,不需要调用 User.find。然后看起来你可以通过 lat,long 作为一个数组
@locations = Location.near([current_user.latitude, current_user.longitude], 50, :order => :distance)
关于ruby-on-rails - Rails、Geocoder 和附近,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11463940/