Skip to content

beste/latlon-geohash-php

Folders and files

NameName
Last commit message
Last commit date
Jan 27, 2025
Jan 19, 2022
Jan 18, 2025
Jan 19, 2022
Jan 19, 2022
Nov 27, 2023
Jan 18, 2025
Jan 19, 2022
Dec 20, 2024
Jul 13, 2024
Jan 18, 2025
Dec 20, 2024
Nov 27, 2023

Repository files navigation

Geohash

Current version Packagist PHP Version Support Tests Sponsor

Library to convert a geohash to/from a latitude/longitude point, and to determine bounds of a geohash cell and find neighbours of a geohash.

This is a PHP implementation based on chrisveness/latlon-geohash. More information (with interactive conversion) at www.movable-type.co.uk/scripts/geohash.html.

Usage

use Beste\Geohash;

// encode latitude/longitude point to geohash of given precision (number of
// characters in resulting geohash); if precision is not specified, it is
// inferred from precision of latitude/longitude values.
Geohash::encode(float $lat, float $lon, ?int $precision = null)

// return { lat, lon } of centre of given geohash, to appropriate precision.
Geohash::decode(string $geohash)

// return { sw, ne } bounds of given geohash.
Geohash::bounds(string $geohash)

// return adjacent cell to given geohash in specified direction (n/s/e/w).
Geohash::adjacent(string $geohash, string $direction)

// return all 8 adjacent cells (n/ne/e/se/s/sw/w/nw) to given geohash.
Geohash::neighbours(string $geohash)

Installation

composer require beste/latlon-geohash

Running tests

composer test