akuechler/laravel-geoly

Perform fast and efficient radius searches on your Laravel Eloquent models.
64,449 41
Install
composer require akuechler/laravel-geoly
Latest Version:v1.0.6
PHP:>=7.1
License:MIT
Last Updated:Apr 20, 2021
Links: GitHub  ·  Packagist
Maintainer: akuechler

Laravel Geoly

Packagist Version PHP from Packagist StyleCI GitHub

Perform fast and efficient radius searches on your Laravel Eloquent models.

Laravel Geoly provides a convenient way for your Laravel Eloquent models to query in a certain radius around a position. It is lightning fast by using a bounding box to cut down the possible results and calculating the distance only on the remaining subset. Laravel Geoly works on both MySQL and PostgreSQL.

Requirements

  • PHP 7.1+
  • Laravel 5+
  • Tested on MySQL and PostgreSQL

Installation

Simply require the project via composer:

$ composer require akuechler/laravel-geoly

How to use

Geoly assumes the two columns latitude and longitude on your eloquent model. Simply add them to your migration if not present yet.

$table->double('latitude');
$table->double('longitude');

If you prefer to use other names for your database columns, specify them in your model.

const LATITUDE  = 'lat';
const LONGITUDE = 'lng';

Use the Geoly package within your Eloquent model.

class YourModel extends Model
{
    use Geoly;
    ...
}

To search for all models within a specific radius around a position, add the radius scope to your query.

$query = YourModel::radius($latitude, $longitude, $radius);
$query->get();

Credits

This project is heavily inspired by Laravel Geographical and Movable Type Scripts article on Selecting points within a bounding circle.

Related Packages

jackpopp/geodistance

Search for locations within a radius using latitude and longitude values with yo...

123,999 125
arcanedev/geo-location

This package allows you to estimate the real-world geographic location of an obj...

11 3
malhal/laravel-geographical

Easily add longitude and latitude columns to your records and use inherited func...

402,351 283
mercurial/geocode

Google Geocoding API for Laravel 4

35 0
jcf/geocode

Google Geocoding API for Laravel

163,245 48