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

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

clonixdev/geokit
================

Geo-Toolkit for PHP

10PHP

Since Dec 7Pushed 3y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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://camo.githubusercontent.com/941ae9d7358d4fe5052d227ec5deda35b16db26a8893e1dcdf99ffb86a2780b4/68747470733a2f2f7472617669732d63692e6f72672f6a736f722f67656f6b69742e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/jsor/geokit?branch=master)[![Code Coverage](https://camo.githubusercontent.com/0a7b9165d6e787c46ad8ecc9625e48efb4bae380406cc3538866343a5c9127b0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a736f722f67656f6b69742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jsor/geokit/?branch=master)

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

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)

### Math

[](#math)

A Math instance can be used to perform geographic calculations on Position and BoundingBox instances.

The [World Geodetic System 1984](http://en.wikipedia.org/wiki/World_Geodetic_System)(WGS84) is exclusively used as the coordinate reference system.

```
$math = new Geokit\Math();
```

#### Distance calculations

[](#distance-calculations)

A math instance provides two methods to calculate the distance between 2 points on the Earth's surface:

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

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

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

#### Transformations

[](#transformations)

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

```
$circlePolygon = $math->circle(
    new Geokit\Position(8.50207515, 49.50042565),
    Geokit\Distance::fromString('5km'),
    32
);
```

#### Other calculations

[](#other-calculations)

Other useful methods are:

- `heading(Geokit\Position $from, Geokit\Position $to)`: Calculates the (initial) heading from the first point to the second point in degrees.
- `midpoint(Geokit\Position $from, Geokit\Position $to)`: Calculates an intermediate point on the geodesic between the two given points.
- `endpoint(Geokit\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.

### Distance

[](#distance)

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

```
$distance = new Geokit\Distance(1000); // Defaults to meters
// or
$distance = new Geokit\Distance(1, Geokit\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.

```
$distance = Geokit\Distance::fromString('1000'); // Defaults to meters
$distance = Geokit\Distance::fromString('1000m');
$distance = Geokit\Distance::fromString('1km');
$distance = Geokit\Distance::fromString('100 miles');
$distance = Geokit\Distance::fromString('100 yards');
$distance = Geokit\Distance::fromString('1 foot');
$distance = Geokit\Distance::fromString('1 inch');
$distance = Geokit\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.

```
$position = new Geokit\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.

```
$southWest = new Geokit\Position(2, 1);
$northEast = new Geokit\Position(2, 1);

$boundingBox = new Geokit\BoundingBox($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.

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

$shrinkedBoundingBox = $boundingBox->shrink(
    Geokit\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.

```
$polygon = new Geokit\Polygon([
    new Geokit\Position(0, 0),
    new Geokit\Position(1, 0),
    new Geokit\Position(1, 1)
]);

$closedPolygon = $polygon->close();

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

$polygon->contains(Geokit\Position(0.5, 0.5)); // true

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

License
-------

[](#license)

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

Credits
-------

[](#credits)

Geokit has been inspired and/or contains ported code from the following libraries:

- [OpenLayers](https://github.com/openlayers/openlayers)
- [GeoPy](https://github.com/geopy/geopy)
- [scalaz-geo](https://github.com/scalaz/scalaz-geo)
- [geojs](http://code.google.com/p/geojs)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.7% 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/cf9a00bf8bc1d9c910fa472049a250f8f8ebf3ed591cbc78e2d01e251d8de005?d=identicon)[clonixdev](/maintainers/clonixdev)

---

Top Contributors

[![jsor](https://avatars.githubusercontent.com/u/55574?v=4)](https://github.com/jsor "jsor (237 commits)")[![codigowww](https://avatars.githubusercontent.com/u/46723539?v=4)](https://github.com/codigowww "codigowww (3 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)")[![koenpunt](https://avatars.githubusercontent.com/u/351038?v=4)](https://github.com/koenpunt "koenpunt (1 commits)")[![bamarni](https://avatars.githubusercontent.com/u/1205386?v=4)](https://github.com/bamarni "bamarni (1 commits)")

### Embed Badge

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

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

###  Alternatives

[joanhey/adapterman

Use any framework and application with Workerman.

85255.9k1](/packages/joanhey-adapterman)[kunstmaan/seo-bundle

Annotating content with metadata for social sharing and seo purposes cannot be overlooked nowadays. The KunstmaanSeoBundle contains default editing functionality for OpenGraph data, meta descriptions, keywords and titles and Metriweb tags. Because the metatagging and tracking options are always changing, a free field to add custom header information is provided as well.

24130.0k2](/packages/kunstmaan-seo-bundle)

PHPackages © 2026

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