PHP code example of clonix / geokit

1. Go to this page and download the library: Download clonix/geokit 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/ */

    

clonix / geokit example snippets


$math = new Geokit\Math();

$distance1 = $math->distanceHaversine($from, $to);
$distance2 = $math->distanceVincenty($from, $to);

$circlePolygon = $math->circle(
    new Geokit\Position(8.50207515, 49.50042565), 
    Geokit\Distance::fromString('5km'),
    32
);

$distance = new Geokit\Distance(1000); // Defaults to meters
// or
$distance = new Geokit\Distance(1, Geokit\Distance::UNIT_KILOMETERS);

$meters = $distance->meters();
$kilometers = $distance->kilometers();
$miles = $distance->miles();
$yards = $distance->yards();
$feet = $distance->feet();
$inches = $distance->inches();
$nauticalMiles = $distance->nautical();

$distance = Geokit\Distance::fromString('1000'); // Defaults to meters
$distance = Geokit\Distance::fromString('1000m');
$distance = Geokit\Distance::fromString('1km');
$distance = Geokit\Distance::fromString('100 miles');
$distance = Geokit\Distance::fromString('100 yards');
$distance = Geokit\Distance::fromString('1 foot');
$distance = Geokit\Distance::fromString('1 inch');
$distance = Geokit\Distance::fromString('234nm');

$position = new Geokit\Position(181, 91);

$x = $position->x(); // Returns 181.0
$y = $position->y(); // Returns 91.0
$longitude = $position->longitude(); // Returns -179.0, normalized
$latitude = $position->latitude(); // Returns 89.0, normalized

$southWest = new Geokit\Position(2, 1);
$northEast = new Geokit\Position(2, 1);

$boundingBox = new Geokit\BoundingBox($southWest, $northEast);

$southWestPosition = $boundingBox->southWest();
$northEastPosition = $boundingBox->northEast();

$center = $boundingBox->center();

$span = $boundingBox->span();

$boolean = $boundingBox->contains($position);

$newBoundingBox = $boundingBox->extend($position);
$newBoundingBox = $boundingBox->union($otherBoundingBox);

$expandedBoundingBox = $boundingBox->expand(
    Geokit\Distance::fromString('10km')
);

$shrinkedBoundingBox = $boundingBox->shrink(
    Geokit\Distance::fromString('10km')
);

$polygon = $boundingBox->toPolygon();

$polygon = new Geokit\Polygon([
    new Geokit\Position(0, 0),
    new Geokit\Position(1, 0),
    new Geokit\Position(1, 1)
]);

$closedPolygon = $polygon->close();

/** @var Geokit\Position $position */
foreach ($polygon as $position) {
}

$polygon->contains(Geokit\Position(0.5, 0.5)); // true

/** @var Geokit\BoundingBox $boundingBox */
$boundingBox = $polygon->toBoundingBox();