geo / geohash
v1.1.0
2017-08-24 11:05 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2022-02-01 12:27:05 UTC
README
类似于 python-geohash 的简单的 PHP geohash 类。
入门
安装
composer require lvht/geohash
系统要求
您需要 PHP >= 5.4.0。
使用
编码坐标
use Lvht\GeoHash;
echo GeoHash::encode(117.031689,36.65396);
结果为 wwe0x0euu12。
默认精度为 0.00001,可以通过编码方法的第三个参数进行更改。
查找给定 geohash 的邻居
use Lvht\GeoHash;
var_dump(GeoHash::expand('wwe0x0'));
结果为
array(8) {
[0] =>
string(11) "wwe0wc7zzzz"
[1] =>
string(11) "wwe0x17zzzz"
[2] =>
string(11) "wwe0x37zzzz"
[3] =>
string(11) "wwe0wb7zzzz"
[4] =>
string(11) "wwe0x27zzzz"
[5] =>
string(11) "wwe0qz7zzzz"
[6] =>
string(11) "wwe0rp7zzzz"
[7] =>
string(11) "wwe0rr7zzzz"
}
解码 geohash 字符串
Use Lvht\GeoHash;
var_dump(GeoHash::decode('wwe0x0'));
结果为
array(4) {
[0] =>
double(117.0263671875) # min longitude
[1] =>
double(117.03735351562) # max longitude
[2] =>
double(36.650390625) # min latitude
[3] =>
double(36.655883789062) # max latitude
}