从 PHP 检查 Google Map Point 是否在多边形中 [英] Check if Google Map Point is in polygon from PHP

查看:40
本文介绍了从 PHP 检查 Google Map Point 是否在多边形中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法来检查一个点是否是多边形的一部分;这个多边形是从文件加载的.

与这个问题相关的所有答案都用javascript解决了,但我需要在服务器端这样做;这是因为结果不需要作为 webclient 显示给用户,它需要存储起来,以后用作参数来选择该区域(多边形)内的一组用户(使用系统).

我寻找了适用于 PHP 的 Google Maps API,但它看起来根本不存在.我找到了这个,但它与谷歌无关,也关注在前端.

我还寻找了 REST API;将内容加载到我的 php 并对其进行解析相对容易,但看起来 Google 将所有精力都放在了 JS API 上.

有什么解决方法吗?

编辑 1:按照@Spacedman 的要求,文件格式为 KML

澄清 1:我希望谷歌为此提供一个工具(因为它存在于 JS 中);解析文件以通过算法检查是一种可能性,我必须检查它是否正常工作.

解决方案

您是否尝试在您最喜欢的搜索引擎中搜索多边形中的 php 点"?热门:

http://assemblysys.com/php-point-in-polygon-algorithm/

它使用扫描线算法,并且有一些示例.您需要做的就是将多边形文件读取为正确的格式(您忽略了您的格式)并调用该函数.

I've been looking for a way to check if a point is part of a polygon; this polygon is loaded from a file.

All the answers related to this question are solved with javascript, but I require to do this on server-side; this because the result does not need to be shown to the user as a webclient, it needs to be stored and later be used as a parameter to select a group of users (that use the system) inside that area (polygon).

I looked for a Google Maps API for PHP but it looks like it does not exists at all. I found this one, but it is not related to Google and also focuses on the front end.

I also looked for a REST API; it would have been relatively easy to load the content to my php and parse it, but looks like Google put all its efforts on the JS API.

Is there any workaround for this?

Edit 1: As @Spacedman requested, the file format is a KML

Clarification 1: I expected that Google provide a tool for this (as it exists with JS); parsing the file to check via an algorithm is a posibility and I'll have to check if it works properly.

解决方案

Did you try searching for "php point in polygon" in your favourite search engine? Top hit:

http://assemblysys.com/php-point-in-polygon-algorithm/

It uses a scanline algorithm, and there's some examples. All you need to do is read your polygon file into the right format (you neglected to say what format you have) and call the function.

这篇关于从 PHP 检查 Google Map Point 是否在多边形中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆