evasquez / geodistance
There is no license information available for the latest version (1.9) of this package.
1.9
2016-06-21 17:31 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.2.*
This package is not auto-updated.
Last update: 2024-11-07 00:37:59 UTC
README
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.
"evasquez/geodistance": "dev-master"
Add the geodistance trait to your eloquent model and latitude/longitude 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', 'latitude', 'longitude']; }
You can now search for locations within a distance, using miles or kilometers:
$lat = 51.4833; $lng = 3.1833; $table = 'youtable' $locations = Location::within(5, 'miles', $lat, $lng,$table)->get(); $locations = Location::within(5, 'kilometers', $lat, $lng,$table)->get();
You can also search for locations outside a certain distance:
Distances Available
Miles (miles/m) Kilometers (kilometers/km) Nautical Miles (nautical_miles) Feet (feet)