使用Google Maps API v3服务器端检查点在多边形区域内的存在 [英] Server-side checking of a point's existence inside a polygonal area using Google Maps API v3
本文介绍了使用Google Maps API v3服务器端检查点在多边形区域内的存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
我已经在PHP中实现了多边形中的服务器端点。
<?php
// Point-In-Polygon算法测试参数
$ polySides = 4; //多边形有多少个角
$ polyX = array(4,9,11,2); //角的水平坐标
$ polyY = array(10,7,2,2); //角点的垂直坐标
$ x = 3.5; //点
// $ y = 13.5; //
$ y = 3.5之外// //
$ b之内$ b函数pointInPolygon($ polySides,$ polyX,$ polyY,$ x,$ y){
$ j = $ polySides-1;
$ oddNodes = 0;如果($ polyY [$ i]< $ y&& $ polyY [$ j]> =($ i $ 0; $ i <$ polySides; $ i ++) $ y
|| $ polyY [$ j]< $ y&& $ polyY [$ i]> = $ y){
if($ polyX [$ i] +($ $ $ polyY [$ i])/($ polyY [$ j] - $ polyY [$ i])*($ polyX [$ j] - $ polyX [$ i])<$ x){
$ oddNodes =!$ oddNodes; }}
$ j = $ i; }
返回$ oddNodes; }
$ b $ //测试
if(pointInPolygon($ polySides,$ polyX,$ polyY,$ x,$ y)){
echoIs in polygon!;
}
else echo不在多边形中;
?>
这可以修改以适应选择的语言,即。 C#
The logic is: user is editing an existing polygonal area of which extreme points are stored in the database. After editing the modified co-ordinates are updated in the database. Now I need to find whether a certain point exists inside the modified polygon or not. For that I'm assuming I have to do the server-side checking. The client-side checking is easily done by javaScript and that I've done already. The real problem I'm having is to check this on the server-side. Any suggestions?
解决方案
I have implemented server side point in polygon in PHP.
<?php
//Point-In-Polygon Algorithm test parameters
$polySides = 4; //how many corners the polygon has
$polyX = array(4,9,11,2);//horizontal coordinates of corners
$polyY = array(10,7,2,2);//vertical coordinates of corners
$x = 3.5;//point
//$y = 13.5;//Outside
$y = 3.5;//Inside
function pointInPolygon($polySides,$polyX,$polyY,$x,$y) {
$j = $polySides-1 ;
$oddNodes = 0;
for ($i=0; $i<$polySides; $i++) {
if ($polyY[$i]<$y && $polyY[$j]>=$y
|| $polyY[$j]<$y && $polyY[$i]>=$y) {
if ($polyX[$i]+($y-$polyY[$i])/($polyY[$j]-$polyY[$i])*($polyX[$j]-$polyX[$i])<$x) {
$oddNodes=!$oddNodes; }}
$j=$i; }
return $oddNodes; }
//Test
if (pointInPolygon($polySides,$polyX,$polyY,$x,$y)){
echo "Is in polygon!";
}
else echo "Is not in polygon";
?>
This can be modified to suit language of choice ie. C#
这篇关于使用Google Maps API v3服务器端检查点在多边形区域内的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文