PHPackages                             geokit/geokit - 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. geokit/geokit

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

geokit/geokit
=============

Geo-Toolkit for PHP

v1.3.0(9y ago)251924.7k↑11.9%28[8 issues](https://github.com/jsor/geokit/issues)6MITPHPPHP &gt;=5.3.3

Since Jan 16Pushed 4y ago14 watchersCompare

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

READMEChangelog (4)DependenciesVersions (7)Used By (6)

Geokit
======

[](#geokit)

Geokit is a PHP toolkit to solve geo-related tasks like:

- Distance calculations.
- Heading, midpoint and endpoint calculations.
- Rectangular bounding box calculations.

[![Build Status](https://github.com/jsor/geokit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsor/geokit/actions/workflows/ci.yml)[![Coverage Status](https://camo.githubusercontent.com/5c7465987dc41b475f55e09431565faaf75d9777fdd6cc14bf5667f95ea3b052/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6a736f722f67656f6b69742f62616467652e7376673f6272616e63683d6d61696e26736572766963653d676974687562)](https://coveralls.io/github/jsor/geokit?branch=main)

- [Installation](#installation)
- [Reference](#reference)
    - [Distance](#distance)
    - [Position](#position)
    - [BoundingBox](#boundingbox)
    - [Polygon](#polygon)
    - [Functions](#functions)
        - [Distance calculations](#distance-calculations)
        - [Transformations](#transformations)
        - [Other calculations](#other-calculations)
- [License](#license)

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

[](#installation)

Install the latest version with [Composer](https://getcomposer.org).

```
composer require geokit/geokit
```

Check the [Packagist page](https://packagist.org/packages/geokit/geokit) for all available versions.

Reference
---------

[](#reference)

### Distance

[](#distance)

A Distance instance allows for a convenient representation of a distance unit of measure.

```
use Geokit\Distance;

$distance = new Distance(1000); // Defaults to meters
// or
$distance = new Distance(1, Distance::UNIT_KILOMETERS);

$meters = $distance->meters();
$kilometers = $distance->kilometers();
$miles = $distance->miles();
$yards = $distance->yards();
$feet = $distance->feet();
$inches = $distance->inches();
$nauticalMiles = $distance->nautical();
```

A Distance can also be created from a string with an optional unit.

```
use Geokit\Distance;

$distance = Distance::fromString('1000'); // Defaults to meters
$distance = Distance::fromString('1000m');
$distance = Distance::fromString('1km');
$distance = Distance::fromString('100 miles');
$distance = Distance::fromString('100 yards');
$distance = Distance::fromString('1 foot');
$distance = Distance::fromString('1 inch');
$distance = Distance::fromString('234nm');
```

### Position

[](#position)

A `Position` is a fundamental construct representing a geographical position in `x` (or `longitude`) and `y` (or `latitude`) coordinates.

Note, that `x`/`y` coordinates are kept as is, while `longitude`/`latitude` are normalized.

- Longitudes range between -180 and 180 degrees, inclusive. Longitudes above 180 or below -180 are normalized. For example, 480, 840 and 1200 will all be normalized to 120 degrees.
- Latitudes range between -90 and 90 degrees, inclusive. Latitudes above 90 or below -90 are normalized. For example, 100 will be normalized to 80 degrees.

```
use Geokit\Position;

$position = new Position(181, 91);

$x = $position->x(); // Returns 181.0
$y = $position->y(); // Returns 91.0
$longitude = $position->longitude(); // Returns -179.0, normalized
$latitude = $position->latitude(); // Returns 89.0, normalized
```

### BoundingBox

[](#boundingbox)

A BoundingBox instance represents a rectangle in geographical coordinates, including one that crosses the 180 degrees longitudinal meridian.

It is constructed from its left-bottom (south-west) and right-top (north-east) corner points.

```
use Geokit\BoundingBox;
use Geokit\Position;

$southWest = Position::fromXY(2, 1);
$northEast = Position::fromXY(2, 1);

$boundingBox = BoundingBox::fromCornerPositions($southWest, $northEast);

$southWestPosition = $boundingBox->southWest();
$northEastPosition = $boundingBox->northEast();

$center = $boundingBox->center();

$span = $boundingBox->span();

$boolean = $boundingBox->contains($position);

$newBoundingBox = $boundingBox->extend($position);
$newBoundingBox = $boundingBox->union($otherBoundingBox);
```

With the `expand()` and `shrink()` methods, you can expand or shrink a BoundingBox instance by a distance.

```
use Geokit\Distance;

$expandedBoundingBox = $boundingBox->expand(
    Distance::fromString('10km')
);

$shrinkedBoundingBox = $boundingBox->shrink(
    Distance::fromString('10km')
);
```

The `toPolygon()` method converts the BoundingBox to an equivalent Polygon instance.

```
$polygon = $boundingBox->toPolygon();
```

### Polygon

[](#polygon)

A Polygon instance represents a two-dimensional shape of connected line segments and may either be closed (the first and last point are the same) or open.

```
use Geokit\BoundingBox;
use Geokit\Polygon;
use Geokit\Position;

$polygon = Polygon::fromPositions(
    Position::fromXY(0, 0),
    Position::fromXY(1, 0),
    Position::fromXY(1, 1)
);

$closedPolygon = $polygon->close();

/** @var Position $position */
foreach ($polygon as $position) {
}

$polygon->contains(Position::fromXY(0.5, 0.5)); // true

/** @var BoundingBox $boundingBox */
$boundingBox = $polygon->toBoundingBox();
```

### Functions

[](#functions)

Geokit provides several functions to perform geographic calculations.

#### Distance calculations

[](#distance-calculations)

- `distanceHaversine(Position $from, Position $to)`: Calculates the approximate sea level great circle (Earth) distance between two points using the Haversine formula.
- `distanceVincenty(Position $from, Position $to)`: Calculates the geodetic distance between two points using the Vincenty inverse formula for ellipsoids.

```
use function Geokit\distanceHaversine;
use function Geokit\distanceVincenty;

$distance1 = distanceHaversine($from, $to);
$distance2 = distanceVincenty($from, $to);
```

Both functions return a [Distance](#distance) instance.

#### Transformations

[](#transformations)

The `circle()` function calculates a closed circle Polygon given a center, radius and steps for precision.

```
use Geokit\Distance;
use Geokit\Position;
use function Geokit\circle;

$circlePolygon = circle(
    Position::fromXY(8.50207515, 49.50042565),
    Distance::fromString('5km'),
    32
);
```

#### Other calculations

[](#other-calculations)

Other useful functions are:

- `heading(Position $from, Position $to)`: Calculates the (initial) heading from the first point to the second point in degrees.
- `midpoint(Position $from, Position $to)`: Calculates an intermediate point on the geodesic between the two given points.
- `endpoint(Position $start, float $heading, Geokit\Distance $distance)`: Calculates the destination point along a geodesic, given an initial heading and distance, from the given start point.

License
-------

[](#license)

Copyright (c) 2011-2022 Jan Sorgalla. Released under the [MIT License](LICENSE).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 98.2% 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 ~438 days

Recently: every ~348 days

Total

6

Last Release

2677d ago

Major Versions

v0.1.0 → v1.0.02015-03-27

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

v1.0.0PHP &gt;=5.3.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/5de14776bbddf901c6e24d35829fe66fe997c303d53aca83cc7d1a90bb0b7110?d=identicon)[jsor](/maintainers/jsor)

---

Top Contributors

[![jsor](https://avatars.githubusercontent.com/u/55574?v=4)](https://github.com/jsor "jsor (271 commits)")[![bamarni](https://avatars.githubusercontent.com/u/1205386?v=4)](https://github.com/bamarni "bamarni (1 commits)")[![koenpunt](https://avatars.githubusercontent.com/u/351038?v=4)](https://github.com/koenpunt "koenpunt (1 commits)")[![luka-dev](https://avatars.githubusercontent.com/u/43535027?v=4)](https://github.com/luka-dev "luka-dev (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![rossity](https://avatars.githubusercontent.com/u/21282907?v=4)](https://github.com/rossity "rossity (1 commits)")

---

Tags

boundsdistancegeogeographygeometrylatlngphppolygongeometrygeographygeo

### Embed Badge

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

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

###  Alternatives

[brick/geo

GIS geometry library

245862.1k15](/packages/brick-geo)[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k8.6M22](/packages/mjaschen-phpgeo)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[geo-io/interface

Geo I/O base interfaces.

626.1M7](/packages/geo-io-interface)[jsor/doctrine-postgis

Spatial and Geographic Data with PostGIS and Doctrine.

2191.6M1](/packages/jsor-doctrine-postgis)[creof/geo-parser

Parser for geography coordinate strings

624.4M15](/packages/creof-geo-parser)

PHPackages © 2026

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