简体   繁体   English

geokit-rails使路线通过近2点

[英]geokit-rails getting the route passing close to 2 points

I'm having a route model 我有一个route模型

class Route < ActiveRecord::Base
  has_many :etapes
  acts_as_mappable :through => :steps
end

and a step one (that contains lat and lgn) step (包含lat和lgn)

class Step ActiveRecord::Base
  belongs_to :route
  acts_as_mappable
end

Actually, I can get the routes passing close to one point with the in_range scope : Route.joins(:steps).in_range(0..15, :origin => [lat, lng]).group(:id) 实际上,我可以使用in_range范围获得经过近一点的in_rangeRoute.joins(:steps).in_range(0..15, :origin => [lat, lng]).group(:id)

I'm trying to get the route passing close to 2 steps , acts_as_mappable does not have the scope I need, so I'm wondering what the best way to go ? 我正在尝试使route传递接近2 stepsacts_as_mappable没有我需要的范围,所以我想知道最好的方法是什么?

Well, to those having similar issue, I did it like this. 好吧,对于那些有类似问题的人,我是这样做的。

Given a hash with 4 points (2 lat and lng); 给定一个具有4点的哈希值(2纬度和经度);

ids = Route.joins(:steps).in_range(0..15, :origin => [hash[:lat1], hash[:lng1]]).group(:id).map(&:id)
routes = Route.joins(:steps).in_range(0..15, :origin => [hash[:lat2], hash[:lng2]]).group(:id)
routes.select {|route| ids.include? route.id}

I first take the routes in range with my first point, then the routes in range with my second point and I select in my first routes only the one in the second routes. 我首先选择第一个点在范围内的路线,然后选择第二个点在范围内的路线,然后在第一条路线中仅选择第二条路线中的一条路线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM