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

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

serafim/geokit
==============

Geo-Toolkit for PHP

v1.4.0(4y ago)15.5k↓83.3%1MITPHPPHP ^8.0

Since Jan 16Pushed 4y agoCompare

[ Source](https://github.com/SerafimArts/geokit)[ Packagist](https://packagist.org/packages/serafim/geokit)[ Docs](https://github.com/SerafimArts/geokit)[ RSS](/packages/serafim-geokit/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

Geokit
======

[](#geokit)

This is fork of 1.x branch of [https://github.com/nickdnk/geokit](nickdnk/geokit)compatible with PHP 8.0+.

 [![](https://github.com/SerafimArts/geokit/workflows/build/badge.svg)](https://github.com/SerafimArts/geokit/actions) [![](https://camo.githubusercontent.com/a50b10d41b40370708a883d6ab970a6cd37db91602093dbc66b0c0d94209bcae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302e302d6666303134302e737667)](https://packagist.org/packages/serafim/geokit) [![Latest Stable Version](https://camo.githubusercontent.com/9e931cf195ed5c57ea5c4373f336be1151dfc5ba888db363d14c535cfaa7b4fc/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f67656f6b69742f76657273696f6e)](https://packagist.org/packages/serafim/geokit) [![Latest Unstable Version](https://camo.githubusercontent.com/8e4bf791ac538f86424515d3bc631f519fa5b9385acc37160880a00873f7e48e/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f67656f6b69742f762f756e737461626c65)](https://packagist.org/packages/serafim/geokit) [![Total Downloads](https://camo.githubusercontent.com/ab6a0d1079ac11f9d73bf17804007bb76b5e0fb230e1fd9353092b6b92f0c867/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f67656f6b69742f646f776e6c6f616473)](https://packagist.org/packages/serafim/geokit) [![](https://camo.githubusercontent.com/b39adf071c4ec02152d1ef62da0ddc25acbfe9685b33817f5a535057c31c6f10/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f67656f6b69742f6c6963656e7365)](https://raw.githubusercontent.com/SerafimArts/geokit/master/LICENSE)

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

- Distance calculations.
- Heading, midpoint and endpoint calculations.
- Rectangular bounds calculations.
- [Installation](#installation)
- [Reference](#reference)

    - [Math](#math)
        - [Distance calculations](#distance-calculations)
        - [Transformations](#transformations)
        - [Other calculations](#other-calculations)
    - [Distance](#distance)
    - [LatLng](#latlng)
    - [Bounds](#bounds)
    - [Polygon](#polygon)
- [License](#license)
- [Credits](#credits)

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

[](#installation)

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

```
composer require serafim/geokit
```

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

Reference
---------

[](#reference)

### Math

[](#math)

A Math instance can be used to perform geographic calculations on LatLng and Bounds instances. Since such calculations depend on an [Earth Ellipsoid](http://en.wikipedia.org/wiki/Earth_ellipsoid), you can pass an instance of `Geokit\Ellipsoid` to its constructor. If no Ellipsoid instance is provided, it uses the default [WGS 86 Ellipsoid](http://en.wikipedia.org/wiki/World_Geodetic_System).

```
$math = new Geokit\Math();
$mathAiry = new Geokit\Math(Geokit\Ellipsoid::airy1830());
```

#### Distance calculations

[](#distance-calculations)

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

- `distanceHaversine($from, $to)`: Calculates the approximate sea level great circle (Earth) distance between two points using the Haversine formula.
- `distanceVincenty($from, $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)

With the `expand` and `shrink` methods, you can expand/shrink a given Bounds or LatLng instance by a distance.

```
$expandedBounds1 = $math->expand(['lat' => 49.50042565 'lng' => 8.50207515], '10km');
$expandedBounds2 = $math->expand(Geokit\Bounds::normalize('-45 179 45 -179'), '10km');

$shrinkedBounds = $math->shrink($expandedBounds2, '10km');
```

#### Other calculations

[](#other-calculations)

Other useful methods are:

- `heading($from, $to)`: Calculates the (initial) heading from the first point to the second point in degrees.
- `midpoint($from, $to)`: Calculates an intermediate point on the geodesic between the two given points.
- `endpoint($start, $heading, $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);
// or
$distance = new Geokit\Distance(1, Geokit\Distance::UNIT_KILOMETERS);

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

Alternatively, you can create a Distance instance through its static normalize method. This method takes anything which looks like distance and generates a Distance object from it.

```
$distance = Geokit\Distance::normalize(1000); // Defaults to meters
$distance = Geokit\Distance::normalize('1000m');
$distance = Geokit\Distance::normalize('1km');
$distance = Geokit\Distance::normalize('100 miles');
$distance = Geokit\Distance::normalize('1 foot');
$distance = Geokit\Distance::normalize('234nm');
```

### LatLng

[](#latlng)

A LatLng instance represents a geographical point in latitude/longitude coordinates.

- Latitude ranges between -90 and 90 degrees, inclusive. Latitudes above 90 or below -90 are capped, not wrapped. For example, 100 will be capped to 90 degrees.
- Longitude ranges between -180 and 180 degrees, inclusive. Longitudes above 180 or below -180 are wrapped. For example, 480, 840 and 1200 will all be wrapped to 120 degrees.

```
$latLng = new Geokit\LatLng(1, 2);

$latitude = $latLng->getLatitude();
// or
$latitude = $latLng['latitude'];

$longitude = $latLng->getLongitude();
// or
$longitude = $latLng['longitude'];
```

Alternatively, you can create a LatLng instance through its static normalize method. This method takes anything which looks like a coordinate and generates a LatLng object from it.

```
$latLng = Geokit\LatLng::normalize('1 2');
$latLng = Geokit\LatLng::normalize('1, 2');
$latLng = Geokit\LatLng::normalize(array('latitude' => 1, 'longitude' => 2));
$latLng = Geokit\LatLng::normalize(array('lat' => 1, 'lng' => 2));
$latLng = Geokit\LatLng::normalize(array('lat' => 1, 'lon' => 2));
$latLng = Geokit\LatLng::normalize(array(1, 2));
```

### Bounds

[](#bounds)

A Bounds 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\LatLng(1, 2);
$northEast = new Geokit\LatLng(1, 2);

$bounds = new Geokit\Bounds($southWest, $northEast);

$southWestLatLng = $bounds->getSouthWest();
// or
$southWestLatLng = $bounds['south_west'];

$northEastLatLng = $bounds->getNorthEast();
// or
$northEastLatLng = $bounds['north_east'];

$centerLatLng = $bounds->getCenter();
// or
$centerLatLng = $bounds['center'];

$spanLatLng = $bounds->getSpan();
// or
$spanLatLng = $bounds['span'];

$boolean = $bounds->contains($latLng);

$newBounds = $bounds->extend($latLng);
$newBounds = $bounds->union($otherBounds);
```

Alternatively, you can create a Bounds instance through its static normalize method. This method takes anything which looks like bounds and generates a Bounds object from it.

```
$bounds = Geokit\Bounds::normalize('1 2 3 4');
$bounds = Geokit\Bounds::normalize('1 2, 3 4');
$bounds = Geokit\Bounds::normalize('1, 2, 3, 4');
$bounds = Geokit\Bounds::normalize(array('south_west' => $southWestLatLng, 'north_east' => $northEastLatLng));
$bounds = Geokit\Bounds::normalize(array('south_west' => array(1, 2), 'north_east' => array(3, 4)));
$bounds = Geokit\Bounds::normalize(array('southwest' => $southWestLatLng, 'northeast' => $northEastLatLng));
$bounds = Geokit\Bounds::normalize(array('southWest' => $southWestLatLng, 'northEast' => $northEastLatLng));
$bounds = Geokit\Bounds::normalize(array($southWestLatLng, $northEastLatLng));
```

### 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\LatLng(0, 0),
    new Geokit\LatLng(0, 1),
    new Geokit\LatLng(1, 1)
]);

$latLng1 = $polygon[0];
$latLng2 = $polygon[1];
$latLng3 = $polygon[2];

$closedPolygon = $polygon->close();

$latLng4 = $closedPolygon[3]; // LatLng(0, 0)

/** @var Geokit\LatLng $latLng */
foreach ($polygon as $latLng) {
}

$polygon->contains(LatLng(0.5, 0.5)); // true

/** @var Geokit\Bounds $bounds */
$bounds = $polygon->toBounds();
```

License
-------

[](#license)

Copyright (c) 2011-2016 Jan Sorgalla. Released under the [MIT License](https://github.com/jsor/geokit/blob/master/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

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 98.8% 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 ~668 days

Recently: every ~635 days

Total

6

Last Release

1578d ago

Major Versions

v0.1.0 → v1.0.02015-03-27

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

v1.0.0PHP &gt;=5.3.3

v1.4.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![jsor](https://avatars.githubusercontent.com/u/55574?v=4)](https://github.com/jsor "jsor (168 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)")

---

Tags

geometrygeographygeo

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[brick/geo

GIS geometry library

2501.3M21](/packages/brick-geo)[geokit/geokit

Geo-Toolkit for PHP

251965.4k6](/packages/geokit-geokit)[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.

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

Geo I/O base interfaces.

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

Spatial and Geographic Data with PostGIS and Doctrine.

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

Parser for geography coordinate strings

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

PHPackages © 2026

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