PHPackages                             imadeous/geohash32 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. imadeous/geohash32

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

imadeous/geohash32
==================

A minimal Base32 geohash encoder/decoder with precision control and mapping support.

00PHPCI failing

Since Aug 2Pushed 9mo agoCompare

[ Source](https://github.com/imadeous/GeoHash32)[ Packagist](https://packagist.org/packages/imadeous/geohash32)[ RSS](/packages/imadeous-geohash32/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

GeoHash32 - Base32 Geohash Encoder/Decoder
==========================================

[](#geohash32---base32-geohash-encoderdecoder)

[![PHP Version](https://camo.githubusercontent.com/c43a736f738fa982a023ed7fc827895810d2ca0f353aa53674e0691bccea1034/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e302d626c7565)](https://php.net)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![Tests](https://github.com/imadeous/geohash32/workflows/Tests/badge.svg)](https://github.com/imadeous/geohash32/actions)[![Packagist Version](https://camo.githubusercontent.com/c8d37f1bd7b42a45932e67c335004bed9451892498610ace2558cbb6e3c99039/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d6164656f75732f67656f686173683332)](https://packagist.org/packages/imadeous/geohash32)

GeoHash32 is a simple, lightweight, and flexible library to **encode** and **decode geohashes** using Base32 encoding. It offers the following features:

- **Variable-length geohashing**: Choose the hash length to adjust precision.
- **Geohash decoding with bounding boxes**: Decode geohashes into latitude, longitude, and bounding box coordinates for spatial operations.
- **QR code generation**: Easily generate QR codes for your geohash to share location info.
- **URL-safe geohashes**: Generate links to share geohashes easily.

---

Purpose
-------

[](#purpose)

This library enables precise encoding and decoding of geographic coordinates (latitude, longitude) into geohashes. The generated geohash can be used in location-based applications for mapping, geofencing, clustering, or spatial queries.

GeoHash32 is particularly useful in scenarios where:

- You need **region-level precision** and are working with **large geographical areas**.
- You want to convert **latitude/longitude** into a **compact, URL-safe string**.
- You need to **encode or decode locations for sharing or comparison** without dependencies.

---

Installation
------------

[](#installation)

You can install **GeoHash32** via Composer:

```
composer require imadeous/geohash32
```

---

Usage
-----

[](#usage)

### Encoding a Geohash

[](#encoding-a-geohash)

```
use GeoHash32\GeoHash32;

$geo = new GeoHash32();
$geo->setHashLength(7);  // Set the geohash length (e.g., 7 for city-level precision)

$hash = $geo->encode(1.3521, 103.8198);  // Singapore coordinates
echo "Geohash: " . $hash;  // Example output: u3xcpme
```

### Decoding a Geohash

[](#decoding-a-geohash)

```
$decoded = $geo->decode('u3xcpme');
echo "Latitude: " . $decoded['lat'] . "\n";
echo "Longitude: " . $decoded['lng'] . "\n";
```

### Generating a URL-safe Geohash

[](#generating-a-url-safe-geohash)

```
$url = $geo->toURL('u3xcpme', 'https://maps.example.com');
echo "Map Link: " . $url;  // Example: https://maps.example.com/h/u3xcpme
```

### Generating a QR Code

[](#generating-a-qr-code)

```
$qr = $geo->toQR('u3xcpme');
echo '';  // Display a base64 QR image
```

---

Key Features
------------

[](#key-features)

- **Customizable Precision**: Set the desired precision by adjusting the hash length.
- **Geohash Decoding with Bounding Box**: Retrieve bounding box coordinates (SW and NE corners) around a geohash.
- **URL-Safe**: Generate URL-safe geohashes for location sharing or mapping.
- **QR Code Generation**: Embed geohashes directly in QR codes for easy scanning or sharing.

---

Use Cases
---------

[](#use-cases)

### Geofencing &amp; Location-Based Services

[](#geofencing--location-based-services)

Use the GeoHash32 library to divide geographic areas into smaller cells and perform spatial queries or geofencing operations based on proximity.

### Map Integration

[](#map-integration)

Generate geohashes for specific locations and plot them on interactive maps (using libraries like Leaflet or Mapbox). Use the toGeoJSON method to export bounding boxes and center points for use in mapping applications.

### URL and QR Code Sharing

[](#url-and-qr-code-sharing)

Encode location data into short geohash strings, which can be used in URLs or converted into QR codes for easy sharing of geolocation information.

### Location Clustering

[](#location-clustering)

Cluster nearby locations together by encoding their coordinates into geohashes. The prefix of the geohash will group geographically close locations together.

### Data Efficiency

[](#data-efficiency)

Use base32-encoded geohashes as compact, efficient representations of geographic points, which can be used in large datasets, mobile apps, or IoT devices.

---

Additional Features
-------------------

[](#additional-features)

- **GeoJSON Export**: Export geohash bounding boxes and center points as GeoJSON for easy integration with map APIs.
- **Performance Benchmarking**: Built-in benchmarking to measure the encoding/decoding speed of geohashes for various precision levels.

---

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Install dependencies
composer install

# Run tests
composer test

# Run tests with coverage
composer test-coverage
```

### Examples

[](#examples)

Check out the `examples/` directory for practical usage demonstrations:

```
php examples/basic_usage.php
```

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

---

License
-------

[](#license)

This package is licensed under the MIT License.

See the LICENSE file for details.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance43

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a5ac2b047893836e886540397d9efcad163af2c445f44a50947079db862f135?d=identicon)[imadeous](/maintainers/imadeous)

---

Top Contributors

[![imadeous](https://avatars.githubusercontent.com/u/20029603?v=4)](https://github.com/imadeous "imadeous (5 commits)")

### Embed Badge

![Health badge](/badges/imadeous-geohash32/health.svg)

```
[![Health](https://phpackages.com/badges/imadeous-geohash32/health.svg)](https://phpackages.com/packages/imadeous-geohash32)
```

###  Alternatives

[symfony/polyfill-php72

Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions

4.8k674.7M31](/packages/symfony-polyfill-php72)[symfony/polyfill-intl-icu

Symfony polyfill for intl's ICU-related data and classes

2.6k251.4M96](/packages/symfony-polyfill-intl-icu)[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.2k64.2M574](/packages/nette-php-generator)[consolidation/site-process

A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call.

5345.3M8](/packages/consolidation-site-process)[sycho/flarum-profile-cover

Adds the ability to add a cover image to a profile.

1836.6k](/packages/sycho-flarum-profile-cover)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
