我拥有所有用户的latitude
和longitude
。我必须从当前纬度和经度中找到靠近我(around 10 miles)
的用户。而且我必须在json中作为回应。我试图为此配置geokit gem,但它向我显示了一些错误,如
WARNING: geokit-rails requires the Geokit gem. You either don't have the gem installed,
or you haven't told Rails to require it. If you're using a recent version of Rails:
config.gem "geokit" # in config/environment.rb
and of course install the gem: sudo gem install geokit
所以我搬到了地理编码器。我应该如何处理这个地理编码器以找到具有上述条件的用户?请帮我。
答案 0 :(得分:1)
class User < ActiveRecord::Base
geocoded_by :address
after_validation :geocode, if: :address_changed?
end
User.near([latitude, longitude], 10).to_json
# or even simpler since current_user is a geocoded object (i.e has lat/long)
User.near(current_user, 10).to_json