ccinn / geohash
此包最新版本(v1.0)无可用许可证信息。
基于GeoHash算法的PHP类库实现。
v1.0
2018-01-30 05:57 UTC
This package is auto-updated.
Last update: 2024-09-29 05:08:10 UTC
README
基于GeoHash算法的PHP类库实现。
详细信息请参阅博客(中文)
https://usblog.crazylaw.cn/index.php/archives/324/
用法
提供三种API方法。
-
around($lng, $lat, $interceptLength = 0)
将经纬度的9个区域的HashCode进行转换。 -
encode($lng, $lat, $interceptLength = 0)
将HashCode转换为指定的经纬度。 -
distance($centerLng, $centerLat, $pointLng, $pointLat, $lenType = 1, $decimal = 2)
计算两个经纬度之间的距离。
示例:
require_once 'vendor/autoload.php'; // The base hashcode length must be a multiple of 5, otherwise it will automatically be filled to a multiple of 5. // The longer the base length of hashcode is, the more options are available to intercept, and the longer it is recommended. 10 is usually enough. $hashCodeLength = 10; $geohash = new ccinn\GeoHash($hashCodeLength); // Search nearby 20 meters $interceptLength = 8; $around = $geohash->around(113.314748, 23.125851, $interceptLength); var_dump($around, $point = $geohash->encode(113.314851, 23.125839, $interceptLength)); if (in_array($point, $around)) { echo 'in_around' . PHP_EOL; } else { echo 'not_in_around' . PHP_EOL; } var_dump('distance:' . $geohash->distance(113.314748, 23.125851, 113.314851, 23.125839) . 'm');