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

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

bogdaan/distance
================

Geo distance library for PHP.

26PHP

Since Jul 21Pushed 10y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHP distance library
====================

[](#php-distance-library)

[![Build Status](https://camo.githubusercontent.com/d37a2f821099b37df57aa3b8a390d98d7c5b2b6af9fb30836e742d34c5642d9c/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f426f676461616e2f44697374616e63652e706e67)](http://travis-ci.org/Bogdaan/Distance)

This library provide:

- distance calculation
- distance matrix calculation

Note that the library does not provide geocoding features (for these purposes, you can use [this library](https://github.com/geocoder-php/Geocoder)).

Example
-------

[](#example)

```
use Distance\Model\Distance;
use Distance\Model\Coordinate;
use Distance\Exception\PoolError;

// for HTTP providers
$client = new GuzzleHttp\Client();

// fail-safe distance source
$pool = new Distance\ProviderPool([

    // Google distance matrix provider
    new Distance\Provider\GoogleProvider($client),

    // OSRM server with distance_table plugin
    new Distance\Provider\OsrmProvider($client, [
        'baseUrl' => 'http://localhost:2233/',
    ]),

    // graphhopper service
    new Distance\Provider\GraphhopperProvider($client,[
        'key' => 'YOU_API_KEY'
    ]),

    // routexl.com distance matrix
    new Distance\Provider\RoutexlProvider($client, [
        'username' => 'YOU_API_USERNAME',
        'password' => 'YOU_API_PASSWORD',
    ]),

    // optinal (If all previous fails) - math provider
    new Distance\Provider\HaversinaProvider(),
]);

// GPS coordinates
$coords = [
    new Coordinate(48.41, 34.81),
    new Coordinate(48.43, 35.22),
    new Coordinate(48.43, 36.22).
];

// case1: single distance
$distanceObject = $pool->getDistance($coords[0], $coords[1]);
$distanceInMeters = $distanceObject->getDistance(Distance::UNIT_METER);
$distanceInMiles = $distanceObject->getDistance(Distance::UNIT_MILE);

// case2: distance matrix 3x3
$matrix = $pool->getDistanceMatrix($coords);
$distanceInMeters = $matrix->getDistance($coords[0], $coords[1], Distance::UNIT_METER);
```

Instalation
-----------

[](#instalation)

Using [composer](http://getcomposer.org):

```
$ composer require bogdaan/distance

```

Providers
---------

[](#providers)

Currently supported providers:

- [Google Distance Matrinx](https://developers.google.com/maps/documentation/javascript/distancematrix)
- [OSRM](https://github.com/Project-OSRM/osrm-backend)
- [Graphhopper](https://graphhopper.com/)
- [Routexl](http://www.routexl.nl/blog/api/)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/380017420e1a00065cfcd2909d20bb285129d73cd128cacc07045968f10513d3?d=identicon)[Bogdan](/maintainers/Bogdan)

---

Top Contributors

[![Bogdaan](https://avatars.githubusercontent.com/u/2012115?v=4)](https://github.com/Bogdaan "Bogdaan (11 commits)")

---

Tags

distancegeophp

### Embed Badge

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

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

###  Alternatives

[touhonoob/rate-limit

PHP rate limiting library with Token Bucket Algorithm

137520.0k2](/packages/touhonoob-rate-limit)[simplesquid/nova-enum-field

A Laravel Nova field to add enums to resources.

52391.9k2](/packages/simplesquid-nova-enum-field)[ballen/distical

A distance (Lat/Long) calculation library for PHP

40180.2k2](/packages/ballen-distical)

PHPackages © 2026

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