gleman17/laravel-geographical
Composer 安装命令:
composer require gleman17/laravel-geographical
包简介
Easily add longitude and latitude columns to your records and use inherited functionality for calculating distances
关键字:
README 文档
README
Easily add longitude and latitude columns to your records and use inherited functionality for calculating distances.
First either update your database or add this to a migration for each model:
$table->double('longitude'); $table->double('latitude');
Finally in your model use:
use Geographical;
1. Distance
Find the distance to all the entries in your table from a particular location.
$query = Model::distance($latitude, $longitude); $asc = $query->orderBy('distance', 'ASC')->get();
2. Geofence
Find all the entries in your table inside a circular geo-fence.
$query = Model::geofence($latitude, $longitude, $inner_radius, $outer_radius); $all = $query->get();
Units
The default unit of distance is miles. You can change it to kilometers by putting this in your model
protected static $kilometers = true;
Notes
- The method returns a
Eloquent\Builderobject so that you can add optional conditions if you want. - If you require to select only a certain columns, it can be achieved by using
select().Model::select('id', 'name')->distance($latitude, $longitude);
(select()should precede thedistance()/geofence()) - You can use
distanceas an aggregate column in the result. (Aggregate columns cannot be used inWHERE, useHAVINGto execute any condition.) - If you use different column names for latitude and longitude, mention them in the Model.php
const LATITUDE = 'lat'; const LONGITUDE = 'lng';
Installation
PHP 5.6.4+ and Laravel 5+ are required.
To get the latest version of Laravel Geographical, simply require the project using Composer:
$ composer require malhal/laravel-geographical
统计信息
- 总下载量: 55
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-06