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

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

redbox/distance
===============

This package allows you to calculate the distance between 2 locations in the world using the Google Maps API

v1.2.5(8y ago)3431MITPHPPHP &gt;=5.4.0CI failing

Since Dec 19Pushed 8y ago3 watchersCompare

[ Source](https://github.com/johnnymast/redbox-distance)[ Packagist](https://packagist.org/packages/redbox/distance)[ RSS](/packages/redbox-distance/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (8)Dependencies (1)Versions (19)Used By (0)

[![Build Status](https://camo.githubusercontent.com/69c96dd8c37591de9f0d75b2600e28c8563026358e6c6f5896fea0fc20a7e924/68747470733a2f2f7472617669732d63692e6f72672f6a6f686e6e796d6173742f726564626f782d64697374616e63652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/johnnymast/redbox-distance)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4882001146b1ade9d6850c5d6f6a99528aa2d7e0a39bf05768c63173fb698c3b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f686e6e796d6173742f726564626f782d64697374616e63652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/johnnymast/redbox-distance/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/01f59d1f80cf3fe987a8fcd85ff4804825816f8d8511d856c725687ab815014b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f686e6e796d6173742f726564626f782d64697374616e63652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/johnnymast/redbox-distance/?branch=master)[![GitHub stars](https://camo.githubusercontent.com/40478dd353dd4db5db1a8aa569ff4ce978c0f3bb20339912919e1707fa15ce59/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4848564d2d52656164792d677265656e2e737667)](http://hhvm.com/)[![Twitter URL](https://camo.githubusercontent.com/bd57172cd5d35575e65898eaf1abad4b23224163dd93edc5e9e00e3609dc1929/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c266c6162656c3d436f6e74616374253230617574686f72)](https://twitter.com/intent/tweet?text=@mastjohnny)

Redbox-distance
===============

[](#redbox-distance)

This set of classes allow you to calculate the distance between Geo Locations or zipcodes. The information comes from the Google Maps API.

Features
--------

[](#features)

- Calculate the distance in
    - Kilometers
    - Miles
    - Yards
- Enable/Disable SSL Verifier
- Set Google MAPS API key (Optional, its not required at this date May 25th of 2015)

### Installing via Composer

[](#installing-via-composer)

Use [composer](http://getcomposer.org) to install this package. Run the Composer command to install the latest stable version of Redbox-distance:

```
composer require redbox/distance
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

### System Requirements

[](#system-requirements)

This package only requires the following:

- Curl
- PHP &gt;= 5.40

Dit will also require **PHPUnit** 4.6 but that will be installed upon installing the package using composer.

### Examples

[](#examples)

Lets calculate the distance between Amsterdam and Rotterdam (Netherlands) using GeoLocations:

```
use Redbox\Distance;

$p1 = new Distance\GeoPoint(52.364533, 4.820374); /* Amsterdam */
$p2 = new Distance\GeoPoint(51.925538, 4.471867); /* Rotterdam */

$tool = new Distance\CalculateDistance();
$distance = $tool->setSource($p1)
                 ->setDestination($p2)
                 ->setUseSslVerifier(false)
                 ->getDistanceInKM();

echo "Example 1";
echo 'The calculated distance is: '.$distance.' KM';

```

Calculate the distance between Den Helder and Haarlem (Netherlands) using posalcodes:

```
use Redbox\Distance;

$p1 = new Distance\GeoZipCode('1781 GC'); /* Den Helder */
$p2 = new Distance\GeoZipCode("2011 SR"); /* Haarlem */

$tool = new Distance\CalculateDistance();
$distance = $tool->setSource($p1)
                 ->setDestination($p2)
                 ->setUseSslVerifier(false)
                 ->getDistanceInKM();

echo "Example 2";
echo 'The calculated distance is: '.$distance.' KM';

```

Other available calculations are:

```
$distance->getDistanceInMiles();

```

and

```
$distance->getDistanceInYards();

```

Troubleshooting
---------------

[](#troubleshooting)

If you get an error regarding SSL connectivity you might want to disable verify peer (CURLOPT\_SSL\_VERIFYPEER). The calculateDistance class offers a method to disable this. Consider using the setUseSslVerifier() method if needed like so.

```
$distance = $tool->setSource($p1)
                 ...
                 ->setUseSslVerifier(false)
                 ...

```

Sometimes the postalcode feature could return wrong results. To battle this also add the country to the postalcode like so.

```
$p1 = new GeoZipCode('1781 GC Netherlands'); /* Den Helder */

```

Author
------

[](#author)

Redbox-distance is created and maintained by [Johnny Mast](mailto:mastjohnny@gmail.com). For feature requests and suggestions you could consider sending me an e-mail.

License
-------

[](#license)

The MIT License

Copyright (c) 2017 Johnny Mast ()

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Total

18

Last Release

3225d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5a228d3118e6b9e3c3c189ea1c8d3a13ed4c9ac312b9217654c81f6d4214cc8?d=identicon)[johnnymast](/maintainers/johnnymast)

---

Top Contributors

[![johnnymast](https://avatars.githubusercontent.com/u/121194?v=4)](https://github.com/johnnymast "johnnymast (59 commits)")

---

Tags

calculationsdistancedistance-calculationpostal-codesredbox-distanceMetricsmapslocationgeogoogle mapsdistancemilesZipcodesKMYards

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k9.3M28](/packages/mjaschen-phpgeo)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k8.5M84](/packages/stevebauman-location)[mediawiki/maps

Adds various mapping features to MediaWiki

84152.3k3](/packages/mediawiki-maps)[matthiasmullie/geo

Geography helper

6379.9k1](/packages/matthiasmullie-geo)[jeroendesloovere/distance

Get distance between two locations using PHP.

3464.4k](/packages/jeroendesloovere-distance)[kartik-v/yii2-ipinfo

An IP address information display widget for Yii 2.0 with country flag and geo position info.

2733.3k1](/packages/kartik-v-yii2-ipinfo)

PHPackages © 2026

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