Rohit
Rohit

Reputation: 677

Get all points that lies within a polygon on Google Map

I am building a Rails Application in which Google map is used for filtering all points on map with drawing tools
File 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


Output

[ [ 44.24519901522129, -77.36572265625 ], [ 42.84375132629021, -69.27978515625 ], [ 34.488447837809304, -67.87353515625 ], [ 36.06686213257888, -81.76025390625 ], [ 42.58544425738491, -81.93603515625 ] ]

How to find all points that lies within these specific co-ordinates
I am using this gem

Upvotes: 0

Views: 671

Answers (1)

Krishna Vyas
Krishna Vyas

Reputation: 285

Possible solution
Kindly use Geokit Gem

Upvotes: 2

Related Questions