Skip to content
H3 v4.4.1 · PHP 8.1+ · FFI

Hexagonal geospatial
indexing for PHP.

H3 PHPbrings Uber’s H3 hexagonal hierarchical geospatial index to PHP through FFI. Index coordinates into hexagonal cells, traverse neighbors, navigate the resolution hierarchy, and measure areas and distances — backed by the official H3 C library.

$composer require foysal50x/h3-php
Geo.php
use Foysal50x\H3\H3;

$h3 = new H3();

// Turn a coordinate into a hexagonal cell at resolution 9 (~174 m)
$cell = $h3->latLngToCell(37.7749, -122.4194, 9);
echo $h3->h3ToString($cell);          // 8928308280fffff

// Read the cell center back out
$center = $h3->cellToLatLng($cell);   // ['lat' => ..., 'lng' => ...]

// Get every cell within 1 step — the cell plus its 6 neighbors
$neighbors = $h3->gridDisk($cell, 1);
echo count($neighbors);               // 7

What is H3?

A global grid that tiles the Earth in hexagons. Every location maps to a hexagonal cell, cells nest into 16 resolutions from continent-scale down to under a meter, and each cell has six equidistant neighbors — making proximity, aggregation, and traversal fast and uniform.

What this package gives you

The full H3 v4.4.1 API in idiomatic PHP — indexing, inspection, traversal, hierarchy, edges, vertices, and measurements — with input validation, memory-safety limits, typed exceptions, and pre-built binaries for every common platform.

Everything the H3 grid offers

A complete binding of the H3 C library — each function documented with accurate signatures and complete, copy-paste examples.

Hexagonal indexing

Convert any latitude/longitude into a single 64-bit hexagonal cell index, and convert it back to a center or boundary at any of 16 resolutions.

Grid traversal

Find neighbors with k-rings, measure grid distance, walk a path between two cells, and trace ring boundaries — all on a uniform hex grid.

Resolution hierarchy

Roll cells up to coarser parents or down to finer children, then compact and uncompact large cell sets for efficient storage.

Measurements

Exact cell areas, edge lengths in km / m / radians, and great-circle distance between coordinates — straight from the H3 C library.

Safe by default

Every input is validated (NaN, Inf, range, null bytes), grid operations are bounded against memory exhaustion, and failures throw a typed H3Exception.

Batteries included

Ships pre-built H3 v4.4.1 binaries for macOS, Linux, and Windows — auto-detected at runtime. No system library to compile.

Based on Uber H3

A faithful binding of H3 v4.4.1, the indexing system that powers ride-sharing, delivery, and logistics at scale.

Real-world ready

Driver matching, delivery zones, geofencing, surge pricing — the docs ship complete, runnable examples.

Pure FFI

No PHP extension to compile. Enable ext-ffi, run composer require, and you are indexing coordinates.

Ready in minutes

Enable the FFI extension, run one Composer command, and you can index your first coordinate. The guide walks you through every step.