PHP code example of back1ng / point-in-mkad

1. Go to this page and download the library: Download back1ng/point-in-mkad library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

back1ng / point-in-mkad example snippets


   
   
   use Back1ng\PointInMkad\Detector;
   use Location\Coordinate;
   
   $detector = new Detector();
   $desiredCoordinate = new Coordinate(55.720375, 37.639101);
   
   if ($detector->isPointInPolygon($desiredCoordinate)) {
       // do smth...
   }

    
    
    use Back1ng\PointInMkad\Detector;
    
    // creating detector...
    
    $detector->getClosestPoint($desiredCoordinate); // Will return Location\Coordinate

    
    
    use Back1ng\PointInMkad\Detector;
    
    // creating detector...
    
    $detector->getDistanceFromOutlinePolygonToCoordinate($desiredCoordinate): float;

    

    use Back1ng\PointInMkad\Polygons\CoordinatePolygon;

    class CustomPolygon extends CoordinatePolygon
    {
        public function get(): array
        {
            return [
                [1, 0],
                [1, 1],
                [0, 1],
            ]
        }
    }

    $polygon = new CustomPolygon();

    $polygon->isValid(); // true
    $polygon->getCentroid(); // Location\Coordinate

    $polygon = new CustomPolygon();

    $detector = new \Back1ng\PointInMkad\Detector(coordinates: $polygon);