<?php
// 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 = $_GET['coordinate'];
$is_inside = false;
// Loop through the array of coordinates
foreach($polygon as $key => $point){
// Check if the coordinate exists in the polygon
if($point['lat'] == $coordinate['lat'] && $point['lng'] == $coordinate['lng']){
$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";
}
}
?>http://mydomain.ru/check_coordinate.php?coordinate=41.063013254638385,57.266932308895065
<?php
const LATITUDE = 0;
const LONGITUDE = 1;
// 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 as $key => $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";
}
}
foreach ($polygon['geometry']['coordinates'] as $point)
http://domain.ru/check_coordinate.php?coordinate=41.06000845574921,57.2617701871141
ini_set('display_errors', '1');
error_reporting(E_ALL);
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
<?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";
}
}
<?php
const LATITUDE = 0;
const LONGITUDE = 1;
const EPSILON = 0.000000000001;
function isEquals( $a, $b ) {
return abs( $a - $b ) < EPSILON;
}
// 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 $polygonPoints){
foreach ( $polygonPoints as $point ) {
// Check if the coordinate exists in the polygon
if( isEquals( $point[LATITUDE], $coordinate[LATITUDE] )
&& isEquals( $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";
}
}