Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoCoding in Rails for polygon bounds [closed]

Is there a way in rails via some mapping API/gem where I can define map areas/map zones (with polygon bounds) and detect if an address falls within a particular zone/area.

like image 981
kitwalker Avatar asked Aug 12 '14 22:08

kitwalker


1 Answers

This is easily done with geokit.

First construct a polygon from LatLng:

polygon = Geokit::Polygon.new([ 
  Geokit::LatLng.new(0,0), 
  Geokit::LatLng.new(10,0), 
  Geokit::LatLng.new(10,10), 
  Geokit::LatLng.new(20,10), 
  Geokit::LatLng.new(20,0), 
  Geokit::LatLng.new(30,0), 
  Geokit::LatLng.new(30,20), 
  Geokit::LatLng.new(0,20)
])

Then you can test if the polygon contains a LatLng:

point = Geokit::LatLng.new(5,5)

polygon.contains?(point) # => true
like image 66
infused Avatar answered Nov 06 '22 14:11

infused