so-tech/yii2-geohash

类似python-geohash的geohash

安装: 85

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

0.1.3 2017-02-09 09:17 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:49:39 UTC


README

描述

生成geohash,这是一种分层空间数据结构,它将空间细分为网格形状的桶,这是已知为Z-order曲线的许多应用之一,通常称为空间填充曲线。更多信息请见 https://en.wikipedia.org/wiki/Geohash

入门指南

安装

composer require sotechn/yii2-geohash

或者添加你的composer.json

"require": {
	...
	"sotechn/yii2-geohash": "~0.1.0"
},

系统要求

你需要 PHP >= 5.4.0Yii ~ 2.0.4

用法

在你的配置文件中

/congig/web.php

添加组件

'components' => [
	...
	'geohash' => [
		'class' => 'sotechn\geohash\Geohash',
	],
]

添加后,你可以使用它

$hash = Yii::$app->geohash->encode($longitude, $latitude, $prec);

你也可以使用模型的行为

public function behaviors()
{
    return [
		...
		['class' => \sotechn\geohash\behaviors\Geohash::className(),]
    ];
}

你可以指定它们要使用的字段和默认项目中使用的精度

[
	'class' => \sotechn\geohash\behaviors\Geohash::className(),
	'fieldLng' => 'longitude', // default 'lng'
	'fieldLat' => 'latitude', // default 'ltd'
	'fieldHash' => 'hash', // default 'geohash'
	'defaultPrec' => '0.00000001', // default 0.00001
]