yameh
@yameh

Почему не работает код на php?

Есть вот такой код:

<?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";
    }
}
?>


И файл с координатами - https://pastebin.com/cBSbSYcS

Делаю запрос формата
http://mydomain.ru/check_coordinate.php?coordinate=41.063013254638385,57.266932308895065


И выдает The coordinate is not inside the polygon. При том, что координата проходит по границе полигона (первая точка в файле с полигоном).
  • Вопрос задан
  • 129 просмотров
Пригласить эксперта
Ответы на вопрос 1
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
А вы сделайте var_dump($_GET['coordinate']); и посмотрите, что вам приходит.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы