此软件包最新版本(v1.2)没有提供许可证信息。

CakePHP 的 GPS 插件

安装: 5

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:cakephp-plugin

v1.2 2016-11-28 09:58 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:09:27 UTC


README

此插件允许根据实体坐标进行搜索。

要求

  • CakePHP 3.x

安装

表条目

添加字段(选择你的名称,或者使用默认的 'latitude' 和 'longitude')。建议使用 FLOAT(10,6)。请注意,如果更改字段名称,必须在插件配置中提供它们。

设置代码

config/bootstrap.php 中添加以下行

Plugin::load('Gps');

并在 src/Model/Table/YourModelTable.php 中添加以下行

class ArticlesTable extends Table
{
    public function initialize(array $config)
    {
    	...
        $this->addBehavior('Gps.Gps');
        ...
    }
}

您还可以通过扩展以下行提供插件配置

class ArticlesTable extends Table
{
    public function initialize(array $config)
    {
    	...
        $this->addBehavior('Gps.Gps',[
        	'radius'=>6896000000.231,
        	'fields'=>[
        		'latitude'=>'lat',
        		'longitude'=>'lon'
        	]
        ]);
        ...
    }
}

例如,在此配置中,我们通知插件表中的字段将命名为 'lat'(纬度)和 'lon'(经度)。地球半径为 6896000000.231 公里。

使用方法

src/Controller/YourModelController 中,例如,在 nearBy 动作中,您可以有

public function nearBy(){
	$yourmodel = $this->YourModel->find('near',['gps'=>$this->request->query]);
	$this->set(compact('yourmodel'));
	$this->set('_serialize',['yourmodel']);
}

因此条件将是 urlencoded 的条件

http://yourdomain.com/youmodel/near-by.json?latitude=43.2&longitude=24.356&radius=20000

通过此 URL,我们告诉我们的 API 软件,获取以 43.224.35 为中心,边长为 20000 米的正方形中的对象