PHP code example of cdekok / geo

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

    

cdekok / geo example snippets


use Cdekok\Geo\Geohash;

// Encode
$hash = (new Geohash)->encode($lat, $lon);

// Decode
$location = (new Geohash)->decode($hash);
echo $location['latitude'] . "\n";
echo $location['longitude'] . "\n";

// Decode bounding box
$bb = (new Geohash)->deodeBbox($hash);
echo 'Min latitude: ' . $bb[0] . "\n";
echo 'Min longitude: ' . $bb[1] . "\n";
echo 'Max latitude: ' . $bb[2] . "\n";
echo 'Max longitude: ' . $bb[3] . "\n";

// Find neighbour hash
$north = (new Geohash)->neighbour($hash, Geohash::DIRECTION_NORTH);

// Find all geohashes within a bounding box
$minLat = -90;
$minLon = -180;
$maxLat = 90;
$maxLon = 180;
$length = 1;
$hashes = (new Geohash)->bboxes($minLat, $minLon, $maxLat, $maxLon, $length);
print_r($hashes);
[
    '0',
    '1',
    '4',
    ...