0

我拥有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

所以我已经转移到地理编码器。我应该如何使用此地理编码器来查找具有上述条件的用户?请帮我。

4

1 回答 1

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
于 2013-09-11T11:32:57.413 回答