GeoCoding in Rails for polygon bounds [closed]

时光怂恿深爱的人放手 提交于 2019-12-03 15:12:48

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!