PHPackages                             philiprehberger/php-geo - 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. philiprehberger/php-geo

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

philiprehberger/php-geo
=======================

Geospatial utilities for distance, bounding box, and point-in-polygon calculations

v1.0.3(1mo ago)11[1 PRs](https://github.com/philiprehberger/php-geo/pulls)MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/php-geo)[ Packagist](https://packagist.org/packages/philiprehberger/php-geo)[ Docs](https://github.com/philiprehberger/php-geo)[ RSS](/packages/philiprehberger-php-geo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

PHP Geo
=======

[](#php-geo)

[![Tests](https://github.com/philiprehberger/php-geo/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-geo/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/d4192862b7c5d5cfd41d1a23dc8f9ccf33555efeac4cf916e02280fac64c8c57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d67656f2e737667)](https://packagist.org/packages/philiprehberger/php-geo)[![License](https://camo.githubusercontent.com/cfffd4c492181122e6d7e09b835fc42ab122f7a2e773aae9035976a2d92ec39a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d67656f)](LICENSE)

Geospatial utilities for distance, bounding box, and point-in-polygon calculations.

---

Requirements
------------

[](#requirements)

DependencyVersionPHP^8.2No external dependencies.

---

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

[](#installation)

```
composer require philiprehberger/php-geo
```

---

Usage
-----

[](#usage)

### Distance Calculation (Haversine)

[](#distance-calculation-haversine)

```
use PhilipRehberger\Geo\Coordinate;
use PhilipRehberger\Geo\Geo;

$nyc = new Coordinate(40.7128, -74.0060);
$la = new Coordinate(33.9425, -118.4081);

$km = Geo::distance($nyc, $la);          // ~3944 km
$miles = Geo::distance($nyc, $la, 'mi'); // ~2451 mi
```

### Vincenty Distance

[](#vincenty-distance)

```
$km = Geo::distanceVincenty($nyc, $la); // More accurate for long distances
```

### Bounding Box

[](#bounding-box)

```
$center = new Coordinate(40.7128, -74.0060);
$box = Geo::boundingBox($center, 10.0); // 10 km radius

$box->contains($center); // true
$box->toArray();          // ['min_lat' => ..., 'max_lat' => ..., 'min_lng' => ..., 'max_lng' => ...]
```

### Point in Polygon

[](#point-in-polygon)

```
$polygon = [
    new Coordinate(40.800, -73.970),
    new Coordinate(40.800, -73.950),
    new Coordinate(40.760, -73.950),
    new Coordinate(40.760, -73.970),
];

$point = new Coordinate(40.780, -73.960);
Geo::contains($polygon, $point); // true
```

### Bearing

[](#bearing)

```
$bearing = Geo::bearing($nyc, $la); // Initial bearing in degrees (0-360)
```

### Midpoint

[](#midpoint)

```
$mid = Geo::midpoint($nyc, $la); // Geographic midpoint
```

### Destination

[](#destination)

```
// Travel 100 km north from the equator
$start = new Coordinate(0.0, 0.0);
$dest = Geo::destination($start, 0.0, 100.0); // bearing=0 (north), 100 km
```

### Units

[](#units)

Supported units: `km` (kilometers), `mi` (miles), `m` (meters), `nmi` (nautical miles).

```
Geo::distance($a, $b, 'mi');   // miles
Geo::distance($a, $b, 'm');    // meters
Geo::distance($a, $b, 'nmi');  // nautical miles
```

---

API
---

[](#api)

MethodDescription`Geo::distance($a, $b, $unit)`Haversine distance between two coordinates`Geo::distanceVincenty($a, $b, $unit)`Vincenty distance between two coordinates`Geo::boundingBox($center, $radius, $unit)`Bounding box around a center point`Geo::contains($polygon, $point)`Point-in-polygon test (ray casting)`Geo::bearing($from, $to)`Initial bearing in degrees`Geo::midpoint($a, $b)`Geographic midpoint`Geo::destination($start, $bearing, $distance, $unit)`Destination from start given bearing and distance---

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

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

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

---

Tags

geogeospatialdistancehaversinepoint in polygonbounding-box

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-geo/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-php-geo/health.svg)](https://phpackages.com/packages/philiprehberger-php-geo)
```

###  Alternatives

[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k8.6M22](/packages/mjaschen-phpgeo)[jmikola/geojson

GeoJSON implementation for PHP

3109.0M77](/packages/jmikola-geojson)[phpmyadmin/shapefile

ESRI ShapeFile library for PHP

281.4M1](/packages/phpmyadmin-shapefile)[matthiasmullie/geo

Geography helper

6377.6k1](/packages/matthiasmullie-geo)

PHPackages © 2026

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