ralphschindler / laragis
为 Laravel 提供地理空间库和一组实用工具
dev-master / 1.0.x-dev
2017-07-22 22:22 UTC
Requires
- php: >=5.5
Requires (Dev)
- illuminate/database: ~5.3
- illuminate/support: ~5.3
- phpunit/phpunit: ~5.5
This package is auto-updated.
Last update: 2024-09-20 22:28:09 UTC
README
LaraGis 为 Laravel 提供地理空间数据库和 Eloquent 功能。
功能
- 简单的实体 API,用于在模型属性中转换
- 通过
ST_AsGeoJSON()
快速序列化从 MySql(非 PHP 用户空间)的地理空间数据
安装
要开始使用 Socialite,将其添加到您的 composer.json
文件中作为依赖项
composer require ralphschindler/laragis
配置
安装 Socialite 库后,在您的 config/app.php
配置文件中注册 LaraGis\LaraGisProvider
'providers' => [ // Other service providers... LaraGis\LaraGisProvider::class, ],
基本用法
要在基于 Eloquent
的模型中使用,使用 LaraGisTrait
,并在 $casts 数组中使用 laragis
键指定要转换为地理空间数据类型的列
class Place extends Model { use LaraGisTrait; protected $table = 'places'; protected $casts = [ 'coordinates' => 'laragis' ]; }
$place = App\Places::find(1); $coordinates = $place->coordinates; echo $coordinates->getLatitudeLongitude(); // "30, -90"
实体 API
/** * @property double $latitude * @property double $longitude */ class Coordinates { public function __construct($latitude = null, $longitude = null); public function setLatitude($latitude); public function getLatitude(); public function setLongitude($longitude); public function getLongitude(); public function castToString($separator, $coordinatesOrder = self::LATITUDE_FIRST) } class Area implements \IteratorAggregate, \Countable { public function addCoordinates(Coordinates $coordinates); public function getCoordinates(); }