Проверка нахождения точки внутри МКАД - amel-post/bitrix.help GitHub Wiki

 function inPoly($x,$y){
     $xp =
        [
            55.867480578856274,
            55.858406154570794,
            55.849329601395034,
            55.8460460684741,
            55.8425690829273,
            55.838512205049284,
            55.83503454278745,
            55.83174979717776,
            55.81454863983515,
            55.805848518081824,
            55.79076368039029,
            55.78321906073592,
            55.748372419923996,
            55.71214405016912,
            55.691444205062076,
            55.68252249473368,
            55.66059743944831,
            55.62661835201399,
            55.60038568135282,
            55.595577868484064,
            55.57603525181336,
            55.571853224118954,
            55.57340937969864,
            55.59305051804366,
            55.60315893895923,
            55.618460205619726,
            55.642880736802,
            55.651326210672124,
            55.65763485374406,
            55.66103139255489,
            55.68516809621123,
            55.691835082634306,
            55.69571341059173,
            55.705407540088274,
            55.715099254996375,
            55.73878005392402,
            55.76356264780353,
            55.77645898801406,
            55.81427064471724,
            55.82225192717148,
            55.827276774959955,
            55.835295854670356,
            55.89194668471719,
            55.89448846438435,
            55.89545302924713,
            55.895549484408974,
            55.89815368275542,
            55.90191499268624,
            55.91011145055837,
            55.91129951553613,
            55.90609271579066,
            55.89644864008169,
            55.888844275739295,
            55.8852746550032,
            55.88344147839087,
            55.88286256244986,
            55.88276607561672,
            55.88025733341599,
            55.87168705668289,
            55.869756716362815,
            55.867480578856274,
        ];
     $yp =
        [
            37.405971326416015,
            37.39738825756836,
            37.39223841625979,
            37.391551770751946,
            37.39361170727541,
            37.39567164379884,
            37.396014966552734,
            37.39532832104492,
            37.39120844799805,
            37.38674525219727,
            37.373355664794936,
            37.36957911450196,
            37.36913077029064,
            37.386640230739864,
            37.41228186471822,
            37.416401737765085,
            37.4332245527065,
            37.47373663766742,
            37.504635685518984,
            37.5128073138559,
            37.594346467908636,
            37.665585939344204,
            37.68120712464692,
            37.73270553773287,
            37.75605148499849,
            37.78333950154868,
            37.823645206766564,
            37.835661503153275,
            37.83943805344625,
            37.83978137620014,
            37.83140125356288,
            37.82922954760215,
            37.8290578862252,
            37.833692743402935,
            37.83832760058067,
            37.84099934169966,
            37.842992184363894,
            37.84283123769986,
            37.838711364652994,
            37.83680870329899,
            37.832688830252124,
            37.81758262908025,
            37.706660179077105,
            37.697467386694974,
            37.6710315346442,
            37.66107517478092,
            37.637042582007496,
            37.61747318503483,
            37.586745798560216,
            37.57625817613987,
            37.53008126573949,
            37.50690697985082,
            37.488069884004496,
            37.476053587617784,
            37.467985502900966,
            37.4612907091998,
            37.4499610583209,
            37.43914639157284,
            37.41339391261291,
            37.409274039566014,
            37.405971326416015,
        ];

     $npol = count($xp);
     $j = $npol - 1;
     $c = 0;
     for ($i = 0; $i < $npol;$i++){
         if (((($yp[$i]<=$y) && ($y<$yp[$j])) || (($yp[$j]<=$y) && ($y<$yp[$i]))) &&
             ($x > ($xp[$j] - $xp[$i]) * ($y - $yp[$i]) / ($yp[$j] - $yp[$i]) + $xp[$i])) {
             $c = !$c;
        }
         $j = $i;
     }
     return $c;
 }