canylmz / laravel-postgis
此包用于计算或检查点与其他数据库点之间的距离。
v0.0.1
2019-10-19 16:58 UTC
Requires
- php: >=7.2
- laravel/framework: ^6.0
- phaza/laravel-postgis: ^4.0
This package is auto-updated.
Last update: 2024-09-30 01:21:43 UTC
README
此包用于计算或检查点与其他数据库点之间的距离。
安装
需要 PHP >=7.2 和 Laravel 6.0。
该包使用 Laravel postgis 扩展 来处理 Laravel 中的 PostgreSQL 数据库点,因此如果需要更多详细信息或如何启用 PHP 中的 postgis 扩展,请参阅前面的链接。
要获取 Laravel 6 PostGIS 的最新版本,只需使用 Composer 引入项目即可。
composer require canylmz/laravel-postgis
用法
1. 首先在你的模型中使用 Postgis
特性
<?php namespace App; use Canylmz\Postgis\Postgis; use Illuminate\Database\Eloquent\Model; class UserLocation extends Model { use Postgis; }
2. 默认情况下,包假设点列的名称为 location
,如果你想更改它,请在你的模型中重写 location
变量
protected $location = "my_column";
3. 默认情况下,包假设距离的单位为 meter
,如果你想更改它,请在你的模型中重写 unit
变量
protected $unit = "km"; //units avialble [mile, km, meter]
函数
1. withDistance
获取点与其他点之间的距离
UserLocation::withDistance(new Point($atitude,$longitude)) ->with("user") ->whereIn("user_id", $users) ->get();
2. whereDistance
检查数据库中一个点与其他点之间的距离
UserLocation::whereDistance(new Point($atitude,$longitude), ">", 50) ->with("user") ->whereIn("user_id", $users) ->get();