igzard/php-geohash

Geohash calculation in PHP

v1.0.1 2025-01-22 09:15 UTC

This package is auto-updated.

Last update: 2025-01-22 09:17:11 UTC


README

๐ŸŒ Geohash calculation in PHP

Tests passed Total Downloads Latest Version

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.