Ruby on rails 使用Geokit Rails,如何查找距离内的所有字段或将位值设置为1
我有一个项目,用户可以在其位置的指定距离内搜索结果,例如,在其邮政编码的10英里范围内。我正在为此使用geokit rails,使用简单的Ruby on rails 使用Geokit Rails,如何查找距离内的所有字段或将位值设置为1,ruby-on-rails,ruby-on-rails-4,rails-activerecord,geokit,Ruby On Rails,Ruby On Rails 4,Rails Activerecord,Geokit,我有一个项目,用户可以在其位置的指定距离内搜索结果,例如,在其邮政编码的10英里范围内。我正在为此使用geokit rails,使用简单的 .within(@distance, :origin => @latlng) 但是,有些结果不依赖于位置,因此我希望它们始终出现在搜索中,如果应该包括,则将由名为“remote”的位属性表示为1 所以我需要做的是能够搜索距离小于X或远程等于1的所有结果 有没有办法做到这一点,或者我必须进行2 db调用并合并结果 非常感谢已从库中删除了距离属性,但有一
.within(@distance, :origin => @latlng)
但是,有些结果不依赖于位置,因此我希望它们始终出现在搜索中,如果应该包括,则将由名为“remote”的位属性表示为1
所以我需要做的是能够搜索距离小于X或远程等于1的所有结果
有没有办法做到这一点,或者我必须进行2 db调用并合并结果
非常感谢已从库中删除了距离属性,但有一些解决方法可以解决“再次包含”(已包含)如何使用“远程”属性为属性距离添加条件的问题
module Geokit::ActsAsMappable
module ClassMethods
# Overwrite Geokit `within`
def within(distance, options = {})
options[:within] = distance
# Have to copy the options because `build_distance_sql` will delete them.
conditions = distance_conditions(options.dup)
sql = build_distance_sql(options)
self.select(
"#{sql} AS #{self.distance_column_name}, #{table_name}.*"
).where(conditions)
end
# Overwrite Geokit `by_distance`
def by_distance(options = {})
sql = build_distance_sql(options)
self.select("#{sql} AS #{self.distance_column_name}, #{table_name}.*"
).order("#{self.distance_column_name} ASC")
end
private
# Copied from geokit-rails/lib/geokit-rails/acts_as_mappable.rb
# Extract distance_sql building to method `build_distance_sql`.
def build_distance_sql(options)
origin = extract_origin_from_options(options)
units = extract_units_from_options(options)
formula = extract_formula_from_options(options)
distance_sql(origin, units, formula)
end
end
end