sotechn/yii2-geohash

geohash like python-geohash

Installs: 85

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

0.1.3 2017-02-09 09:17 UTC

This package is not auto-updated.

Last update: 2024-04-22 12:55:57 UTC


README

Description

Generate geohash, it is a hierarchical spatial data structure which subdivides space into buckets of grid shape, which is one of the many applications of what is known as a Z-order curve, and generally space-filling curves. See more https://en.wikipedia.org/wiki/Geohash

Getting Started

Install

composer require sotechn/yii2-geohash

or add your composer.json

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

System Requirements

You need PHP >= 5.4.0, Yii ~ 2.0.4

Usage

in your config file

/congig/web.php

added component:

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

after you've added it, you can use it

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

and you can also use behavior with model

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

you can specify their fields to be used and precision that you use in your default project:

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