Skip to content

sotechn/yii2-geohash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Yii-2 Geohash

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
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages