Php 在多边形内查找纬度和经度的点

Php 在多边形内查找纬度和经度的点,php,google-maps,polygon,point-in-polygon,Php,Google Maps,Polygon,Point In Polygon,这是我的代码,我修改并从这个问题中提取 顶点x和y形成一个矩形。我仍然无法使它工作,即使点y和x在多边形内,它没有显示正确的结果。我在这里做错了什么 <?php $vertices_x = array(45.007243,45.007243,46.3734,46.3734); // x-coordinates of the vertices of the polygon $vertices_y = array(-75.007095,-72.506332,-72.506332,-75.007

这是我的代码,我修改并从这个问题中提取

顶点x和y形成一个矩形。我仍然无法使它工作,即使点y和x在多边形内,它没有显示正确的结果。我在这里做错了什么

<?php
$vertices_x = array(45.007243,45.007243,46.3734,46.3734); // x-coordinates of the vertices of the polygon
$vertices_y = array(-75.007095,-72.506332,-72.506332,-75.007095,); // y-coordinates of the vertices of the polygon
$points_polygon = count($vertices_x); 
$latitude_y =  45.5086699;  // x-coordinate of the point to test
$longitude_x = -73.553992; 

if (is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y)){
  echo "Is in polygon!";
}
else 
{
echo "Is not in polygon";
}

function is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y)
{
  $i = $j = $c = 0;
  for ($i = 0, $j = $points_polygon-1 ; $i < $points_polygon; $j = $i++) {
    if ( (($vertices_y[$i] > $latitude_y != ($vertices_y[$j] > $latitude_y)) &&
    ($longitude_x < ($vertices_x[$j] - $vertices_x[$i]) * ($latitude_y - $vertices_y[$i]) / ($vertices_y[$j] - $vertices_y[$i]) + $vertices_x[$i]) ) ) 
        $c = !$c;
  }
  return $c;
}
?>

一个问题是纬度y和经度x变量的初始化:

latitude_y appears to contain the 'x' coordinate.
longitude_x appears to contain the 'y' coordinate.