获取 Google 地图上多边形内的所有点
Get all points that lies within a polygon on Google Map
我正在构建一个 Rails 应用程序,其中 Google 地图用于使用绘图工具过滤地图上的所有点
文件 Model.rb
class Model < ActiveRecord::Base
geocoded_by :address, :latitude => :lat, :longitude => :lng
def address
[city, state].compact.join(', ')
end
end
controller.rb
def in_bounds
unless params[:polygon].nil?
poly = params[:polygon].split('),(').map{|k| k = k.gsub(/[()]/, "")}
all_points = []
poly.each do |p|
all_points.push (p.split(',').collect(&:strip).map{ |k| k = k.to_f})
end
render json: all_points
return
end
end
输出
[
[
44.24519901522129,
-77.36572265625
],
[
42.84375132629021,
-69.27978515625
],
[
34.488447837809304,
-67.87353515625
],
[
36.06686213257888,
-81.76025390625
],
[
42.58544425738491,
-81.93603515625
]
]
如何找到位于这些特定坐标内的所有点
我正在使用这个 gem
可能solution
请使用 Geokit Gem
我正在构建一个 Rails 应用程序,其中 Google 地图用于使用绘图工具过滤地图上的所有点
文件 Model.rb
class Model < ActiveRecord::Base
geocoded_by :address, :latitude => :lat, :longitude => :lng
def address
[city, state].compact.join(', ')
end
end
controller.rb
def in_bounds
unless params[:polygon].nil?
poly = params[:polygon].split('),(').map{|k| k = k.gsub(/[()]/, "")}
all_points = []
poly.each do |p|
all_points.push (p.split(',').collect(&:strip).map{ |k| k = k.to_f})
end
render json: all_points
return
end
end
输出
[ [ 44.24519901522129, -77.36572265625 ], [ 42.84375132629021, -69.27978515625 ], [ 34.488447837809304, -67.87353515625 ], [ 36.06686213257888, -81.76025390625 ], [ 42.58544425738491, -81.93603515625 ] ]
如何找到位于这些特定坐标内的所有点
我正在使用这个 gem
可能solution
请使用 Geokit Gem