igzard / php-geohash
Geohash calculation in PHP
Requires
- php: ^8.3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2025-01-22 09:17:11 UTC
README
๐ Geohash calculation in PHP
The PHP Geohash Generator is a simple yet powerful tool that converts geographic coordinates (latitude and longitude) into a compact and highly useful geohash string. Perfect for efficiently storing, searching, and managing spatial data in your applications! ๐
What is a Geohash? ๐ค
A geohash is an algorithm that divides the Earth into progressively smaller "boxes" and encodes the coordinates as a text string.
- In short: A geohash is a single string representation of a specific location on Earth.
- Benefits:
- Compact and human-readable format.
- Easy to compare: if two locations are close, their geohashes share the same prefix.
- Ideal for fast searches and spatial grouping.
Why use this library? ๐ฏ
- Easy to use: Simply provide latitude and longitude, and get a geohash in return.
- Precision-focused: The algorithm supports up to 12-character geohashes for highly accurate encoding.
- Perfect for location-based applications: Whether storing spatial data, searching for locations, or displaying maps, this tool gets the job done efficiently.
Installation & Usage ๐ ๏ธ
Requires PHP 8.3+
composer require igzard/php-geohash
use Igzard\Geohash\Geohash; // Generate a geohash for a specific location with latitude and longitude coordinates. echo Geohash::generate(47.497913, 19.040236); // input: Budapest coordinates | output: u2mw1q8xmssz // Generate a geohash with custom precision (default is 12), latitude interval, and longitude interval. echo Geohash::generate(47.497913, 19.040236, [ 'precision' => 10, 'latitude_interval' => [ 'min' => -70, 'max' => 10, ], 'longitude_interval' => [ 'min' => -80, 'max' => 170, ], ]);
Contributing ๐ค
Thank you for considering contributing to the Geohash PHP library! ๐ Here is some tooling to help you get started:
โ Run Code quality check:
make code-quality
๐ท Run PHPUnit tests:
make phpunit
๐จ Run php-cs-fixer:
make php-cs-fixer
๐ฅ Run phpstan:
make phpstan
๐ Install dependencies with composer:
make composer-install
Geohash PHP was created by Gergely Ignรกcz under the MIT license.