Google 地图:获取用户绘制的多边形内包含的点?
当地的一位房地产经纪人想要将 Google 地图添加到他的网站上以显示他的列表。然而,他希望网站访问者能够在地图上绘制任意多边形,单击按钮,然后显示这些边界内的所有房屋,而不只是向其所有属性显示地图标记。
我的理解是,这需要一些 GIS 巫术。但在我开始研究 PostGIS 的复杂性之前,我想知道是否有更好的方法来做到这一点?该网站在标准 LAMP 堆栈上运行,但我希望说服他转向 Python/Nginx/PostgreSQL。
A local real estate agent is wanting to add Google maps to his web site that display his listings. However, rather than just showing map markers to all his properties, he wants the web site visitor to be able to draw an arbitrary polygon on the map, click a button, and then display all his houses within those bounds.
My understanding is that this is going to take some GIS voodoo. But before I start looking into the complexity of PostGIS, I'm wondering if there's a better way to do this? The site runs on a standard LAMP stack, but I'm hoping to convince him to move over to Python/Nginx/PostgreSQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为没有必要迁移到 PostGIS。
编辑
另一种方式点谷歌地图中的-in-polygon
I don't think there is a need to move to PostGIS.
EDIT
another way of doing point-in-polygon in google maps
我认为这并不需要您想象的那么多 GIS 巫毒。我将分三个步骤来解决这个问题:
为每个列表生成纬度和经度坐标。您的数据库中可能已经有此信息。如果您不这样做,有几个免费工具可以用来执行此操作。我们在工作中编写了一个 Google 地图应用程序,该应用程序直接链接到我们的 SQL 后端基础设施,如果需要,我可以帮助您在应用程序中进行设置。
使用 GLatLng 返回受访者感兴趣的任意点的坐标:http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GLatLng
使用一些数学方法来创建点的区域(如果您只允许任意形状使用 4 个点,则会更容易)并且然后使用 for 循环将每个列表的纬度/经度对与面积进行比较。
如果您的区域太大而无法将所有列表与任意区域进行比较,请根据州/县/城市/您拥有的任何数据进行一些预过滤。
希望这有帮助,
-追赶
I don't think this is going to require as much GIS voodoo as you think. I would approach this in three steps:
Generate a latitude and longitude coordinate for each listing. You may already have this information in your database. If you don't, there are several free tools available to do this. We have programmed a Google maps application at work that links directly to our SQL backend infrastructure that I can help you set up in your application if needed.
Use GLatLng to return coordinates for the arbitrary points the respondent is interested in: http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GLatLng
Use some math to create an area of the points (will be easier if you only allow 4 points for the arbitrary shape) and then use a for loop to compare each listing's lat/long pair to the area.
If your area is too large to compare all listings to the arbitrary area, do some pre-filtering based on state/county/city/whatever data you have available.
Hope this helps,
-Chase