PHPackages                             ricklab/location - 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. ricklab/location

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

ricklab/location
================

A library of PHP objects for spatial calculations

v7.0.0(10mo ago)1533.0k↓38.9%5BSD-3-ClausePHPPHP ^8.1CI passing

Since Aug 18Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/rickogden/Location)[ Packagist](https://packagist.org/packages/ricklab/location)[ RSS](/packages/ricklab-location/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (35)Used By (0)

PHP Location Library [![CI](https://github.com/rickogden/Location/actions/workflows/ci.yaml/badge.svg)](https://github.com/rickogden/Location/actions/workflows/ci.yaml)
========================================================================================================================================================================

[](#php-location-library-)

A library for geospatial calculations in PHP.

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

[](#installation)

Using composer, run `composer require ricklab/location`

Usage
-----

[](#usage)

A brief example of how this library can be used:

```
use Ricklab\Location\Calculator\VincentyCalculator;
use Ricklab\Location\Converter\DegreesMinutesSeconds;
use Ricklab\Location\Converter\Unit;
use Ricklab\Location\Geometry\GeometryCollection;
use Ricklab\Location\Geometry\Point;
use Ricklab\Location\Geometry\LineString;
use Ricklab\Location\Geometry\BoundingBox;

// Usage of Point
$point = new Point(-2.34323, 52.43343);

// Numeric-strings are also valid, to reduce floating-point errors
$point2 = new Point('-2.50002', '54.343211');

// Calculate the distance using the default calculator (Haversine) in meters
$distance = $point->distanceTo($point2);

// Calculate the distance between two points in miles using the Vincenty formula
$distance = $point->distanceTo($point2, Unit::MILES, new VincentyCalculator());

// Usage of LineString
$line = new LineString([$point, $point2]);

// Create a point from DMS strings
$point3 = Point::fromDms(
    DegreesMinutesSeconds::fromString('40° 26′ 46.2345″ S'),
    DegreesMinutesSeconds::fromString('79° 58′ 56.5543″ E'),
);
// A geometry collection example
$multiGeometry = new GeometryCollection([
    $line,
    $point3,
]);

// Usage of bounding box
$bbox = BoundingBox::fromCenter($point, 1000); // 1000 meters radius
$bbox2 = BoundingBox::fromGeometry($multiGeometry); // Bounding box of the line
$contains = $bbox2->contains($point2); // true if the point is within the bounding box

// A new GeometryCollection with the new bounding-box polygon
$newMultiGeometry = $multiGeometry->withGeometry($bbox->getPolygon());
```

Transformers
------------

[](#transformers)

Transformers are used to convert geometries to and from various formats. This library includes a GeoJSON, WKT and WKB transformer.

### GeoJsonTransformer

[](#geojsontransformer)

The `GeoJsonTransformer` class converts geometries into GeoJSON format.

##### Usage

[](#usage-1)

Here is an example of how to use the `GeoJsonTransformer` class:

```
use Ricklab\Location\Transformer\GeoJsonTransformer;
use Ricklab\Location\Geometry\Point;

$geometry = new Point($longitude, $latitude);
$geoJsonString = GeoJsonTransformer::encode($geometry);

$secondGeometry = GeoJsonTransformer::decode($geoJsonString);

echo $geoJsonString;
```

### WktTransformer/WkbTransformer

[](#wkttransformerwkbtransformer)

The `WktTransformer` and `WkbTransformer` class converts geometries into WKT format.

### Usage

[](#usage-2)

Here is an example of how to use the `WktTransformer` class:

```
use Ricklab\Location\Transformer\WktTransformer;
use Ricklab\Location\Geometry\Point;

$geometry = new Point($longitude, $latitude);
$wktString = WktTransformer::encode($geometry);

echo $wktString;
```

`WkbTransformer` works in exactly the same way, but returns a binary string.

Features
--------

[](#features)

The `Feature` class represents a single geospatial feature from the GeoJSON spec.

### Usage

[](#usage-3)

Here is an example of how to use the `Feature` class:

```
use Ricklab\Location\Feature\Feature;
use Ricklab\Location\Geometry\Point;

$geometry = new Point($longitude, $latitude);
$feature = new Feature(['property-name', 'property-value'], $geometry);

$geometry = $feature->getGeometry();
$properties = $feature->getProperties();
```

FeatureCollection
-----------------

[](#featurecollection)

The `FeatureCollection` class represents a collection of geospatial features.

### Usage

[](#usage-4)

Here is an example of how to use the `FeatureCollection` class:

```
use Ricklab\Location\Feature\Feature;
use Ricklab\Location\Feature\FeatureCollection;
use Ricklab\Location\Geometry\Point;
use Ricklab\Location\Transformer\GeoJsonTransformer;

$feature1 = new Feature(['name' => 'Feature 1'], new Point($longitude1, $latitude1));
$feature2 = new Feature(['name' => 'Feature 1'], new Point($longitude2, $latitude2));

$collection = new FeatureCollection([$feature1, $feature2], true);

$features = $collection->getFeatures();
$bbox = $collection->getBbox(); // Returns the bounding box of the collection
$featureGeoJson = GeoJsonTransformer::encode($features); // GeoJSON feature collection representation
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance73

Regular maintenance activity

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 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 ~189 days

Recently: every ~416 days

Total

22

Last Release

315d ago

Major Versions

v2.2.1 → v3.0.0-rc12016-01-05

v3.0.0 → v4.0.02018-12-05

v4.1.3 → v5.0.02020-01-27

v5.0.1 → v6.0.0-rc.12020-12-14

v6.0.2 → v7.0.02025-07-07

PHP version history (8 changes)1.2.x-devPHP &gt;=5.3

v2.1PHP &gt;=5.4

v2.2.1PHP &gt;=5.4|^7.0

v4.0.0PHP ^7.1

v5.0.1PHP ^7.1|^8.0

v6.0.0-rc.1PHP ^7.4|^8.0

v6.0.1PHP ^7.4 || ^8.0

v7.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/135672?v=4)[Rick Ogden](/maintainers/rickogden)[@rickogden](https://github.com/rickogden)

---

Top Contributors

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

---

Tags

geolocationlocationgisgeospatialgeo-location

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[torann/geoip

Support for multiple Geographical Location services.

2.2k14.2M76](/packages/torann-geoip)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[midnite81/geolocation

A laravel package which wraps the IP Info DB and IP2Location Services

3624.1k](/packages/midnite81-geolocation)[markbaker/quadtrees

QuadTree implementation in PHP

1739.2k](/packages/markbaker-quadtrees)[tabgeo/country

geoip (only countries) php library (http://tabgeo.com)

1158.8k](/packages/tabgeo-country)

PHPackages © 2026

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