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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With