Documentation
¶
Overview ¶
Package geohash 提供经纬度的 Geohash 编码/解码、邻居计算与覆盖查询,纯标准库。
Geohash 把二维经纬度编码成一个 base32 字符串:前缀相同的两点在地理上相邻, 前缀越长精度越高。因此"附近的人/店铺/开播"可退化为**字符串前缀匹配**—— 在 Redis/DB 里按 geohash 前缀建索引即可范围检索,无需专门的空间数据库。
与 pkg/spatial 的区别(互补):
- spatial 是平面网格索引(float64 x/y),适合游戏地图这类"局部平面坐标";
- geohash 面向真实地球经纬度(WGS84),适合 LBS——编码后可直接用字符串前缀 跨进程/落库检索,不必把全部实体加载进内存。
精度参考(geohash 长度 → 单元约尺寸):
4 → ~39km,5 → ~4.9km,6 → ~1.2km,7 → ~153m,8 → ~38m,9 → ~4.8m。
边界说明:Geohash 的"同前缀=相邻"在单元边界处有裂缝——两个物理相邻的点可能 落在不同前缀。做邻近搜索时应取中心单元 + 其 8 个邻居一起查(见 Neighbors/ CoverNeighbors),再对候选做精确距离过滤。
纯函数,无状态,并发安全。
Index ¶
- func CoverNeighbors(lat, lng float64, precision int) []string
- func DecodeCenter(hash string) (lat, lng float64)
- func Distance(lat1, lng1, lat2, lng2 float64) float64
- func Encode(lat, lng float64, precision int) string
- func Neighbor(hash string, dLat, dLng int) string
- func Neighbors(hash string) []string
- type Box
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoverNeighbors ¶
CoverNeighbors 返回中心单元 + 其 8 个邻居共 9 个 Geohash(去重), 用作邻近搜索的候选前缀集合:先按这些前缀检索,再对结果做精确距离过滤。
func DecodeCenter ¶
DecodeCenter 解码并返回单元中心点坐标(便捷封装)。
Types ¶
Click to show internal directories.
Click to hide internal directories.