PHPackages                             jeroendesloovere/distance - 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. jeroendesloovere/distance

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

jeroendesloovere/distance
=========================

Get distance between two locations using PHP.

1.0.2.1(11y ago)3462.8k↓28.3%6MITPHPPHP &gt;=5.3.3

Since Apr 2Pushed 3y ago3 watchersCompare

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

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Distance class
==============

[](#distance-class)

[![Latest Stable Version](https://camo.githubusercontent.com/7961a8d19c76b517c4b96900663aa64307c6cb82760e9a0a82ef994836be21d6/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a65726f656e6465736c6f6f766572652f64697374616e63652e737667)](https://packagist.org/packages/jeroendesloovere/distance)[![License](https://camo.githubusercontent.com/5a911ddcd16b9110e7821386ffd8d637005a8b856c14a3c0861b955e91da4eba/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d6c69676874677265792e737667)](https://github.com/jeroendesloovere/distance/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/4444cedd18d1cf346713763e8668a23a448cc4441d3f26576865b447e225b499/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6a65726f656e6465736c6f6f766572652f64697374616e63652e737667)](https://travis-ci.org/jeroendesloovere/distance)

Get distance between two locations using PHP. The distance is getting calculated based on latitude and logitude variables and without using any other external class.

Usage
-----

[](#usage)

### Installing using Composer

[](#installing-using-composer)

When using [Composer](https://getcomposer.org) you can always load in the latest version.

```
{
    "require": {
        "jeroendesloovere/distance": "1.0.*"
    }
}
```

> Check [in Packagist](https://packagist.org/packages/jeroendesloovere/distance).

### Example

[](#example)

**Setting our example data**

```
use JeroenDesloovere\Distance\Distance;

// first location
$latitude1 = '50.8538510000';
$longitude1 = '3.3550450000';

// second location
$latitude2 = '50.8325600000';
$longitude2 = '3.4787650000';
```

**Get distance between two locations**

```
$distance = Distance::between(
    $latitude1,
    $longitude1,
    $latitude2,
    $longitude2
);

// dump data
echo 'Distance between the two locations = ' . $distance . ' km';
```

**Get closest distance from location 1 to one of the two locations (2 and 3)**

```
// third location
$latitude3 = '50.8865040000';
$longitude3 = '3.4320850000';

// define multiple items
$items = array(
    array(
        'title' => 'location 2',
        'latitude' => $latitude2,
        'longitude' => $longitude2
    ),
    array(
        'title' => 'location 3',
        'latitude' => $latitude3,
        'longitude' => $longitude3
    )
);

$distance = Distance::getClosest(
    $latitude1,
    $longitude1,
    $items
);

// dump data
echo 'The closest location to location 1 is ' . $distance['title'] . ' and the distance between them is ' . $distance['distance'] . ' km';
```

Documentation
-------------

[](#documentation)

The class is well documented inline. If you use a decent IDE you'll see that each method is documented with PHPDoc.

Contributing
------------

[](#contributing)

It would be great if you could help us improve this class. GitHub does a great job in managing collaboration by providing different tools, the only thing you need is a [GitHub](http://github.com) login.

- Use **Pull requests** to add or update code
- **Issues** for bug reporting or code discussions
- Or regarding documentation and how-to's, check out **Wiki**More info on how to work with GitHub on help.github.com.

License
-------

[](#license)

The module is licensed under [MIT](./LICENSE.md). In short, this license allows you to do everything as long as the copyright statement stays present.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 97.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 ~137 days

Total

4

Last Release

4017d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/588616?v=4)[Jeroen Desloovere](/maintainers/jeroendesloovere)[@jeroendesloovere](https://github.com/jeroendesloovere)

---

Top Contributors

[![jeroendesloovere](https://avatars.githubusercontent.com/u/588616?v=4)](https://github.com/jeroendesloovere "jeroendesloovere (44 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (1 commits)")

---

Tags

distancelatitudelongitudephpphplocationdistancecoordinates

### Embed Badge

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

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

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[fjw/color-compare

A library for converting colors (Hex, RGB, HSL, CIELAB (LAB), DIN-99) and calculating color distances based on DIN-99.

1310.0k](/packages/fjw-color-compare)

PHPackages © 2026

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