cdekok/geo

Geohash library port of ngeohash

1.0.1 2017-09-28 17:19 UTC

This package is not auto-updated.

Last update: 2024-11-10 03:31:07 UTC


README

PHP implementation for encoding / decoding geohashes

Build Status Coverage Status

Usage

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',
    ...

Credits

PHP port of ngeohash