Laravel 0 – 13
No commit activity in last 2 years
No release in over 2 years
There's a lot of open issues
Search for locations within a radius using latitude and longitude values with your eloquent models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

GeoDistance

GeoDistance allows you to search for locations within a radius using latitude and longitude values with your eloquent models.

###Setup

Add geodistance to your composer file.

"jackpopp/geodistance": "dev-master"

Add the geodistance trait to your eloquent model and lat/lng columns to your table.

<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Jackpopp\GeoDistance\GeoDistanceTrait;

class Location extends Model {

    use GeoDistanceTrait;

    protected $fillable = ['name', 'lat', 'lng'];
    
}

You can now search for locations within a distance, using miles or kilometers:

$lat = 51.4833;
$lng = 3.1833;

$locations = Location::within(5, 'miles', $lat, $lng)->get();

$locations = Location::within(5, 'kilometers', $lat, $lng)->get();

// or 

$location = new Location();
$locations = $location->lat($lat)->lng($lng)->within(5, 'miles')->get();

You can also search for locations outside a certain distance:

$lat = 51.4833;
$lng = 3.1833;

$locations = Location::outside(100, 'miles', $lat, $lng)->get();

$locations = Location::outside(100, 'kilometers', $lat, $lng)->get();

// or 

$location = new Location();
$locations = $location->lat($lat)->lng($lng)->outside(100, 'miles')->get();

Distances Available

Miles (miles/m) Kilometers (kilometers/km) Nautical Miles (nautical_miles) Feet (feet)

If you wish to add addtional measurements, please create a new issue.

Credit to movable-type.co.uk for information on selecting points withing a bounding circle - http://www.movable-type.co.uk/scripts/latlong-db.html