<?php
const LATITUDE = 0;
const LONGITUDE = 1;
var_dump($_GET['coordinate']);
ini_set('display_errors', '1');
error_reporting(E_ALL);
// Read the content of the json file
$json_file = file_get_contents('polygon.json');
// Decode the json content into an array of coordinates
$polygon = json_decode($json_file, true);
// Check if the request contains a coordinate to be verified
if(isset($_GET['coordinate'])){
$coordinate = explode(', ', $_GET['coordinate']); // запятая с пробелом
$is_inside = false;
// Loop through the array of coordinates
foreach ($polygon['geometry']['coordinates'] as $point){
// Check if the coordinate exists in the polygon
// можно проще: if ($point == $coordinate) {
if($point[LATITUDE] == $coordinate[LATITUDE] && $point[LONGITUDE] == $coordinate[LONGITUDE]){
$is_inside = true;
break;
}
}
// Output a positive or negative message
if($is_inside){
echo "The coordinate is inside the polygon";
}else{
echo "The coordinate is not inside the polygon";
}
}
string(38) "41.063013254638385, 57.266932308895065"
<br />
<b>Notice</b>: Undefined index: coordinates in <b>/home/c/co03498/rdcntnt/public_html/test/check_coordinate.php</b> on line <b>19</b><br />
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/c/co03498/rdcntnt/public_html/test/check_coordinate.php</b> on line <b>19</b><br />
The coordinate is not inside the polygon
http://domain.ru/check_coordinate.php?coordinate=41.06000845574921,57.2617701871141
upd: именно в первой координате точке (lat), во второй (lng) все хорошо