PHPackages                             iroid/laravel-haversine - 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. iroid/laravel-haversine

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

iroid/laravel-haversine
=======================

Laravel package for calculating distances using the Haversine formula

112804PHP

Since Feb 23Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/salman1802/laravel-haversine)[ Packagist](https://packagist.org/packages/iroid/laravel-haversine)[ RSS](/packages/iroid-laravel-haversine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Haversine
=================

[](#laravel-haversine)

Laravel Haversine is a package that provides utilities for calculating distances between geographical points using the Haversine formula. It includes a method that can be used with Laravel's Eloquent ORM to easily calculate distances between database records and a given point.

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

[](#installation)

You can install the package via Composer. Run the following command in your terminal:

```
composer require iroid/laravel-haversine
```

The package will automatically register itself.

Usage
-----

[](#usage)

### Calculating Distance

[](#calculating-distance)

You can use the `Haversine::distance()` method to calculate the distance between two geographical points using the Haversine formula. This method returns the distance in kilometers by default.

```
use Iroid\LaravelHaversine\Haversine;

$latitudeFrom = 40.7128; // Latitude of point A
$longitudeFrom = -74.0060; // Longitude of point A
$latitudeTo = 34.0522; // Latitude of point B
$longitudeTo = -118.2437; // Longitude of point B

$distanceInKm = Haversine::distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo);
```

### Using Different Units

[](#using-different-units)

You can specify the unit of measurement for the distance by passing an additional parameter to the `distance()` method. Supported units include kilometers (default), miles, nautical miles, and meters.

```
$distanceInMiles = Haversine::distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, 'miles');
$distanceInNauticalMiles = Haversine::distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, 'nautical_miles');
$distanceInMeters = Haversine::distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, 'meters');
```

### Using with Laravel Eloquent

[](#using-with-laravel-eloquent)

You can use the `applyHaversine()` method provided by the package with Laravel's Eloquent ORM to calculate distances between database records and a given geographical point.

```
use Iroid\LaravelHaversine\Haversine;

$latitudeFrom = 40.7128; // Latitude of the reference point
$longitudeFrom = -74.0060; // Longitude of the reference point

// Example: Retrieving places sorted by distance from the reference point
$places = Place::applyHaversine($latitudeFrom, $longitudeFrom)
                ->orderBy('distance')
                ->get();
```

#### Parameters for `applyHaversine()`

[](#parameters-for-applyhaversine)

- `$query`: The Eloquent query builder instance.
- `$latitudeFrom`: Latitude of the reference point.
- `$longitudeFrom`: Longitude of the reference point.
- `$latitudeColumn` (optional): Custom column name for latitude in the database table. Defaults to `'latitude'`.
- `$longitudeColumn` (optional): Custom column name for longitude in the database table. Defaults to `'longitude'`.
- `$unit` (optional): Unit of measurement for the distance. Supported units are kilometers (default), miles, nautical miles, and meters.

You can use these parameters to customize the behavior of the `applyHaversine()` method according to your database schema and requirements.

Credits
-------

[](#credits)

Interested to contribute or modification contact me [email](mailto:salman.iroid@gmail.com).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance54

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity21

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c04f37057d08c2525a1e784cfd5ad3e029fe720e95d50aab63104c9fb8b3d1f?d=identicon)[salman1802](/maintainers/salman1802)

---

Top Contributors

[![salman-iroid](https://avatars.githubusercontent.com/u/103873893?v=4)](https://github.com/salman-iroid "salman-iroid (4 commits)")

### Embed Badge

![Health badge](/badges/iroid-laravel-haversine/health.svg)

```
[![Health](https://phpackages.com/badges/iroid-laravel-haversine/health.svg)](https://phpackages.com/packages/iroid-laravel-haversine)
```

###  Alternatives

[xsolve-pl/xsolve-cookie-acknowledgement-bundle

XSolve Cookie Acknowledgement Bundle to handle new privacy law

1182.1k](/packages/xsolve-pl-xsolve-cookie-acknowledgement-bundle)

PHPackages © 2026

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