PHPackages                             magutti/magutti-spatial - 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. [Database &amp; ORM](/categories/database)
4. /
5. magutti/magutti-spatial

ActiveLibrary[Database &amp; ORM](/categories/database)

magutti/magutti-spatial
=======================

Laravel Builder Mysql Spatial Extension

V7.0.0(1mo ago)42.5k↓48%1MITPHPPHP ^7.4|^8.0|^8.1|^8.2|^8.3

Since Sep 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/marcoax/maguttiSpatialBuilder)[ Packagist](https://packagist.org/packages/magutti/magutti-spatial)[ Docs](https://github.com/marcoax/maguttiSpatialBuilder)[ GitHub Sponsors](https://github.com/feross)[ GitHub Sponsors](https://github.com/standard)[ RSS](/packages/magutti-magutti-spatial/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (16)Used By (0)

magutti-spatial V4
==================

[](#magutti-spatial-v4)

Laravel Builder Mysql Spatial Extension

[![Latest Stable Version](https://camo.githubusercontent.com/ce5a330d29cbef83736c7d411800a1bf3dc159203831b38cda12749386bde084/687474703a2f2f706f7365722e707567782e6f72672f6d6167757474692f6d6167757474692d7370617469616c2f76)](https://packagist.org/packages/magutti/magutti-spatial)[![Total Downloads](https://camo.githubusercontent.com/3dc2495edf882ac95881ea7234ee90134f9c723a5c1a11003a169bbef9416c0c/687474703a2f2f706f7365722e707567782e6f72672f6d6167757474692f6d6167757474692d7370617469616c2f646f776e6c6f616473)](https://packagist.org/packages/magutti/magutti-spatial)[![License](https://camo.githubusercontent.com/6d28d24366c80f15bc55d5729c80c8c37a801c4bd6b590d0f4722503683cd2a0/687474703a2f2f706f7365722e707567782e6f72672f6d6167757474692f6d6167757474692d7370617469616c2f6c6963656e7365)](https://packagist.org/packages/magutti/magutti-spatial)[![PHP Version Require](https://camo.githubusercontent.com/54d4d4af6d853b1afd4652b45f2ec7908513df6544c59c09b36daaab0d7be062/687474703a2f2f706f7365722e707567782e6f72672f6d6167757474692f6d6167757474692d7370617469616c2f726571756972652f706870)](https://packagist.org/packages/magutti/magutti-spatial)

Laravel Builder extensions to calculate distances between two Spatial points using Mysql native function `ST_Distance_Sphere`.

`ST_Distance_Sphere` default unit to find distance is meters.

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

[](#installation)

You can install the package via composer:

```
composer require magutti/magutti-spatial
```

Usage
-----

[](#usage)

Add in your Model

```
use Magutti\MaguttiSpatial\Builders\SpatialBuilder;

class Location extends Model
{
    .......
    // you can override the default longitude and latitude fields
    protected $spatialFields = [
        'lng',
        'lat'
    ];

    function newEloquentBuilder($query): SpatialBuilder
    {
        return new SpatialBuilder($query);
    }
    .......
}
```

### Example of usage

[](#example-of-usage)

Get all points where the distance from a given position are less than 1Km

```
Location::select(['id','lng','lat'])
           ->whitDistance([8.9246844, 45.4152695]) // return distance in meters (default)
           ->whereDistance([8.9246844, 45.4152695],1000)
           ->get()
```

where **8.9246844** (longitude), **45.4152695** (latitude) is your position and **1000** is the max distance in meters.

```
SELECT `id`,
       `lng`,
       `lat`,
       St_distance_sphere(Point(8.9246844, 45.4152695), Point(lng, lat)) * 1 AS
       distance
FROM   `locations`
WHERE  St_distance_sphere(Point(8.9246844, 45.4152695), Point(lng, lat)) whitDistanceInMiles([8.9246844, 45.4152695]) // return distance in Miles
           ->whereDistance([8.9246844, 45.4152695],10,'mi')
           ->get()
```

Find the closest point to you in Km

```
Location::select(['id','lat','lng'])
           ->whitDistanceInKm([8.9246844, 45.4152695])
           ->whereDistance([8.9246844, 45.4152695],10,'km')
           ->closest()
```

Helpers
-------

[](#helpers)

The package provide some pre-built methods to calculate distance in Km, Miles or Feet.

```
whitDistanceInKm(array $point)    -> return distance in Km;
whitDistanceInMiles(array $point) -> return distance in Miles (mi);
whitDistanceInFeet(array $point)  -> return distance in Feet (ft);

and for filtering by distance

whereDistanceInKm(array $point, float $distance)     -> filter point by a given distance in Km
whereDistanceInMiles(array $point, float $distance)  -> filter point by a given distance in Miles
whereDistanceInFeet(array $point, float $distance)   -> filter point by a given distance in Miles
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

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

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [marcoax](https://github.com/magutti)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance63

Regular maintenance activity

Popularity27

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity73

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

Recently: every ~374 days

Total

15

Last Release

58d ago

Major Versions

v2.1.2 → v3.0.02022-02-12

v3.0.0 → V4.0.02023-03-25

V4.0.0 → V5.0.02024-03-16

V5.0.0 → V6.0.02025-03-09

V6.0.0 → V7.0.02026-03-21

PHP version history (4 changes)V1PHP ^7.4|^8.0

V4.0.0PHP ^7.4|^8.0|^8.1

V5.0.0PHP ^7.4|^8.0|^8.1|^8.2

V7.0.0PHP ^7.4|^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

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

---

Top Contributors

[![marcoax](https://avatars.githubusercontent.com/u/6276864?v=4)](https://github.com/marcoax "marcoax (45 commits)")

---

Tags

laravelmysql-spatial

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/magutti-magutti-spatial/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

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