PHPackages                             vpro/geo-calculator - 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. vpro/geo-calculator

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

vpro/geo-calculator
===================

A PHP package for calculating geographical distances

v1.0.0(1y ago)04MITPHPPHP &gt;=7.4

Since Oct 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Victor070656/DistanceCalculator)[ Packagist](https://packagist.org/packages/vpro/geo-calculator)[ RSS](/packages/vpro-geo-calculator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP Geographic Distance Calculator
==================================

[](#php-geographic-distance-calculator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f5ad37078a196a363625bcb67cfc9eee69169880ca72d0638d910a7c55b989da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7670726f2f67656f2d63616c63756c61746f722e737667)](https://packagist.org/packages/vpro/geo-calculator)[![Tests](https://github.com/vpro/geo-calculator/actions/workflows/tests.yml/badge.svg)](https://github.com/vpro/geo-calculator/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/2e8e36000ee6d0975ff60472e20197f9d51c2ad4295689c09768c0a5f23e6655/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7670726f2f67656f2d63616c63756c61746f722e737667)](https://packagist.org/packages/vpro/geo-calculator)[![License](https://camo.githubusercontent.com/283b5137490ae826b2791445a60236707e54da5b1ae6fd25f0ab2f09ab1c5d18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7670726f2f67656f2d63616c63756c61746f722e737667)](https://packagist.org/packages/vpro/geo-calculator)

A PHP package for calculating geographic distances using the Haversine formula. Perfect for applications needing to determine distances between coordinates or check if locations are within a specific radius.

Features
--------

[](#features)

- 🌍 Calculate distances between geographic coordinates
- 📏 Support for both kilometers and miles
- 🎯 Check if points are within a given radius
- 🔄 Convert between different distance units
- 💪 Strong typing with PHP 7.4+ support
- 🧪 Comprehensive test suite

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

[](#installation)

You can install the package via composer:

```
composer require vpro/geo-calculator
```

Usage
-----

[](#usage)

### Basic Distance Calculation

[](#basic-distance-calculation)

```
use GeoCalculator\DistanceCalculator;

$calculator = new DistanceCalculator();

// Calculate distance between New York and London
$distance = $calculator->calculateDistance(
    40.7128, -74.0060,  // New York coordinates
    51.5074, -0.1278    // London coordinates
);

echo "Distance: " . round($distance, 2) . " km";
```

### Check if Point is Within Radius

[](#check-if-point-is-within-radius)

```
// Check if location is within 100km radius
$isNearby = $calculator->isWithinRadius(
    40.7128, -74.0060,  // Center point
    40.7614, -73.9776,  // Point to check
    100,                // Radius
    'km'                // Unit ('km' or 'mi')
);

if ($isNearby) {
    echo "Location is within radius";
}
```

### Convert Between Units

[](#convert-between-units)

```
// Convert 100 kilometers to miles
$miles = $calculator->convertDistance(
    100,    // Distance
    'km',   // From unit
    'mi'    // To unit
);

echo "100 km = " . round($miles, 2) . " miles";
```

API Reference
-------------

[](#api-reference)

### calculateDistance()

[](#calculatedistance)

Calculate the distance between two geographic points.

```
public function calculateDistance(
    float $lat1,
    float $lon1,
    float $lat2,
    float $lon2,
    string $unit = 'km'
): float
```

Parameters:

- `$lat1`: Latitude of first point in degrees
- `$lon1`: Longitude of first point in degrees
- `$lat2`: Latitude of second point in degrees
- `$lon2`: Longitude of second point in degrees
- `$unit`: Unit of measurement ('km' or 'mi', defaults to 'km')

### isWithinRadius()

[](#iswithinradius)

Check if a point is within a specified radius of another point.

```
public function isWithinRadius(
    float $lat1,
    float $lon1,
    float $lat2,
    float $lon2,
    float $radius,
    string $unit = 'km'
): bool
```

Parameters:

- `$lat1`: Latitude of center point in degrees
- `$lon1`: Longitude of center point in degrees
- `$lat2`: Latitude of point to check in degrees
- `$lon2`: Longitude of point to check in degrees
- `$radius`: Radius to check within
- `$unit`: Unit of measurement ('km' or 'mi', defaults to 'km')

### convertDistance()

[](#convertdistance)

Convert distances between different units.

```
public function convertDistance(
    float $distance,
    string $from,
    string $to
): float
```

Parameters:

- `$distance`: Distance to convert
- `$from`: Original unit ('km' or 'mi')
- `$to`: Target unit ('km' or 'mi')

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [V-PRO](https://github.com/Victor070656)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

555d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7aa81173a8e4882ea654a65c2dd74d83afbf5d58a74220a00f59b8ef42ca82ba?d=identicon)[vpro](/maintainers/vpro)

---

Top Contributors

[![Victor070656](https://avatars.githubusercontent.com/u/109238181?v=4)](https://github.com/Victor070656 "Victor070656 (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vpro-geo-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/vpro-geo-calculator/health.svg)](https://phpackages.com/packages/vpro-geo-calculator)
```

###  Alternatives

[winzou/state-machine-bundle

Bundle for the very lightweight yet powerful PHP state machine

34010.4M15](/packages/winzou-state-machine-bundle)[xethron/laravel-4-generators

Rapidly generate resources, migrations, models, and much more.

972.8M10](/packages/xethron-laravel-4-generators)[timacdonald/has-parameters

A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.

228271.7k2](/packages/timacdonald-has-parameters)[cornernote/gii-modeldoc-generator

Gii ModelDoc Generator for Yii framework

13109.1k](/packages/cornernote-gii-modeldoc-generator)[vanthao03596/laravel-hanhchinhvn

hành chính việt nam laravel

406.3k](/packages/vanthao03596-laravel-hanhchinhvn)

PHPackages © 2026

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