lvht/geohash

类似于python-geohash的geohash

v1.1.0 2017-08-24 11:05 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:20:07 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
}