PHPackages                             powlam/coordinates - 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. powlam/coordinates

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

powlam/coordinates
==================

A PHP package to work with coordinates

v1.0.1(1y ago)13MITPHPPHP ^8.3.0CI passing

Since Jan 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/powlam/coordinates)[ Packagist](https://packagist.org/packages/powlam/coordinates)[ Fund](https://www.paypal.com/paypalme/powlam)[ GitHub Sponsors](https://github.com/powlam)[ RSS](/packages/powlam-coordinates/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

 [![Coordinates for Php](https://raw.githubusercontent.com/powlam/coordinates/main/docs/coordinatesLogo.png)](https://raw.githubusercontent.com/powlam/coordinates/main/docs/coordinatesLogo.png)

 [![GitHub Workflow Status (master)](https://camo.githubusercontent.com/ec7d98862ed1748c2401246023e649a18421941f62fd40b4a208003c750a2933/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706f776c616d2f636f6f7264696e617465732f74657374732e796d6c)](https://github.com/powlam/coordinates/actions) [![Total Downloads](https://camo.githubusercontent.com/eca6319436029f936a34bcc6aec756d635759ef84d6c358efb5507fbcb90c655/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706f776c616d2f636f6f7264696e61746573)](https://packagist.org/packages/powlam/coordinates) [![Latest Version](https://camo.githubusercontent.com/63872e90f0a52d7d41e67b7f8406cd0e1a74bacd83daff1d23acdcfb0b442699/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f776c616d2f636f6f7264696e61746573)](https://packagist.org/packages/powlam/coordinates) [![License](https://camo.githubusercontent.com/b592f9b1984bc0bbbbcabdd7c6fc7135dbaeb5231870a66c5f73573d5c19cc0c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706f776c616d2f636f6f7264696e61746573)](https://packagist.org/packages/powlam/coordinates)

---

This package provides a handful of tools to work with **coordinates** the same way as [Google Maps Javascript API](https://developers.google.com/maps/documentation/javascript/reference/coordinates?hl=es-419) does.

> **Requires [PHP 8.3+](https://php.net/releases/)**

Classes
=======

[](#classes)

LatLng class
------------

[](#latlng-class)

A LatLng is a point in geographic coordinates: latitude and longitude. Both parameters are of float type.

- **Latitude** ranges between -90 and 90 degrees inclusive. Values above or below this range will be clamped to the range \[-90, 90\]. This means that if the specified value is less than -90, it will be set to -90. And if the value is greater than 90, it will be set to 90.
- **Longitude** ranges between -180 and 180 degrees inclusive. Values above or below this range will be adjusted to fit within the range. For example, a value of -190 will become 170. A value of 190 will become -170. This reflects the fact that longitudes wrap around the globe.

LatLngAltitude class
--------------------

[](#latlngaltitude-class)

A LatLngAltitude is a 3D point in geographic coordinates: latitude, longitude, and altitude.

- **Altitude** is measured in meters. Positive values indicate heights above ground level, and negative values indicate depths below the ground surface.

LatLngBounds class
------------------

[](#latlngbounds-class)

A LatLngBounds instance represents a rectangle in geographical coordinates, including one that crosses the 180-degree longitudinal meridian.

Features
========

[](#features)

Movement
--------

[](#movement)

Both **LatLng** and **LatLngAltitude** points are movable, so they can be moved in any direction using the **move** method.

```
use Powlam\Coordinates\Enums\Heading;
use Powlam\Coordinates\Enums\Units;
use Powlam\Coordinates\LatLngAltitude;

$latLngAlt = (new LatLngAltitude(1.23, 4.56, 0.0))
    ->move(Heading::NORTH, 10.0)
    ->move(Heading::SOUTH, 1.0)
    ->move(Heading::EAST, 20.0)
    ->move(Heading::WEST, 5.0)
    ->move(Heading::UP, 100.0, Units::METERS)
    ->move(Heading::DOWN, 30.0, Units::METERS);

// at this point $latLngAlt is at (10.23, 19.56, 70.0)
```

Note: Latitude movements stop when reaching the North or South Pole.

### Moving areas

[](#moving-areas)

The **LatLngBounds** rectangles are also movable; the entire area is moved at once.

When moving a **LatLngBounds** rectangle towards east or west using meters or kilometers, the conversion between distance and degrees depends on the latitude. The corresponding degrees will be calculated based on the midpoint latitude of the area.

Interaction between bounds
--------------------------

[](#interaction-between-bounds)

**LatLngBounds** classes can interact with each other:

```
use Powlam\Coordinates\LatLng;
use Powlam\Coordinates\LatLngBounds;

$bounds = new LatLngBounds(new LatLng(1, 1), new LatLng(10, 10));
// $bounds refers to (1, 1|10, 10)

$bounds->intersects(new LatLngBounds(new LatLng(5, 5), new LatLng(15, 15))); // returns true
$bounds->intersects(new LatLngBounds(new LatLng(15, 15), new LatLng(20, 20))); // returns false

$union = $bounds->union(new LatLngBounds(new LatLng(5, 6), new LatLng(15, 16)));
// $union refers to (1, 1|15, 16)
```

Also a **LatLngBounds** can interact with a **LatLng** point:

```
use Powlam\Coordinates\LatLng;
use Powlam\Coordinates\LatLngBounds;

$bounds = new LatLngBounds(new LatLng(1, 1), new LatLng(10, 10));
// $bounds refers to (1, 1|10, 10)

$bounds->contains(new LatLng(5, 5)); // returns true
$bounds->contains(new LatLng(-5, 5)); // returns false

$bounds->extend(new LatLng(15, 16));
// at this point $bounds has been extended to (1, 1|15, 16)
```

Unions and extensions are always done in **the closest way possible**. When talking about the **longitude**, usually there are 2 ways of making the join: towards west or towards east. This library selects the closest one or, in case of a tie, towards east.

Places
======

[](#places)

There is a list of geographical points, lines and areas into the **Place** enum.

Through the **get()** method you can retrieve the underlying **LatLng**, **LatLngAltitude** or **LatLngBounds** object that represents it.

Each of them can be used as any other **LatLng**, **LatLngAltitude** or **LatLngBounds** object.

```
use Powlam\Coordinates\Enums\Place;

$northernHemisphere = Place::NORTHERN_HEMISPHERE->get();

$northernHemisphere->contains(new LatLng(5, 5)); // returns true
```

Utils
=====

[](#utils)

Latitude and Longitude
----------------------

[](#latitude-and-longitude)

These classes facilitate converting between degrees and meters or kilometers in both directions.

This is especially useful in the case of longitudes, because the ratio changes depending on the latitude.

```
use Powlam\Coordinates\Utils\Latitude;
use Powlam\Coordinates\Utils\Longitude;

Latitude::metersPerDegree(); // returns 111319.9
Latitude::degreesFromKilometers(Latitude::KILOMETERS_PER_DEGREE); // returns 1.0

Longitude::metersPerDegree(latitudeDegrees: 0.0); // returns 111319.9
Longitude::metersPerDegree(latitudeDegrees: -45.0); // returns 78715.056171
Longitude::metersPerDegree(latitudeDegrees: -45.0); // returns 78715.056171
Longitude::degreesFromMeters(Longitude::METERS_PER_DEGREE_AT_EQUATOR, latitudeDegrees: 0.0); // returns 1.0
Longitude::degreesFromMeters(Longitude::METERS_PER_DEGREE_AT_EQUATOR, latitudeDegrees: 90.0); // returns INF
Longitude::kilometersFromDegrees(1.0, latitudeDegrees: -45.0); // returns 78.715056
```

FloatCompare
------------

[](#floatcompare)

Testing floating point values for equality [is problematic](https://www.php.net/manual/en/language.types.float.php), due to the way that they are represented internally. To test floating point values for equality, an upper bound on the relative error due to rounding is used. This delta is the smallest acceptable difference in calculations.

The methods implemented into the **FloatCompare** class allow comparing float numbers due to an internal delta value.

```
use Powlam\Coordinates\Utils\FloatCompare;

FloatCompare::equals(1.0, 1.000001); // returns true

FloatCompare::equalOrLessThan(1.0, 0.9999999) // returns true
FloatCompare::equalOrLessThan(1.0, 2.0) // returns true
```

---

📚 The full API of this library is available in [this file](docs/API_DOCUMENTATION.md).

---

**Coordinates for PHP** was created by **[Paul Albandoz](https://github.com/powlam)** under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance42

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

6

Last Release

483d ago

Major Versions

v0.2.2 → v1.0.02025-01-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/05131452f80dca817992232b987e8c48b1162852285e86c8868f91cf7de49ea0?d=identicon)[powlam](/maintainers/powlam)

---

Top Contributors

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

---

Tags

phplatitudelongitudecoordinates

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[anthonymartin/geo-location

Powerful GeoCoding library: Retrieve bounding box coordinates, distances between geopoints, point in polygon, get longitude and latitude from addresses and more with GeoLocation for PHP

196949.5k5](/packages/anthonymartin-geo-location)[data-values/geo

Geographical value objects, parsers and formatters

20631.0k18](/packages/data-values-geo)[jeroendesloovere/distance

Get distance between two locations using PHP.

3462.8k](/packages/jeroendesloovere-distance)[laravie/geotools

Geo-related tools PHP 7+ library

19105.4k1](/packages/laravie-geotools)[adlino/locations

Iran Provinces, Counties and Cities with a Google Map Location for Laravel.

171.3k](/packages/adlino-locations)

PHPackages © 2026

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