https://github.com/bsm/geohashi
Go(lang) clone of geohash-int
https://github.com/bsm/geohashi
Last synced: 9 months ago
JSON representation
Go(lang) clone of geohash-int
- Host: GitHub
- URL: https://github.com/bsm/geohashi
- Owner: bsm
- License: bsd-3-clause
- Created: 2015-11-23T09:17:25.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-28T15:50:49.000Z (almost 9 years ago)
- Last Synced: 2025-08-31T04:02:30.261Z (9 months ago)
- Language: Go
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GeoHashi
[](https://travis-ci.org/bsm/geohashi)
[](http://godoc.org/github.com/bsm/geohashi)
[](https://goreportcard.com/report/github.com/bsm/geohashi)
[](https://opensource.org/licenses/MIT)
Geohash library for Go, optimised for performance. Inspired by [geohash-int](https://github.com/yinqiwen/geohash-int).
## Examples
Encode coordinates:
```go
func Encode() {
lat, lon := 51.52463, -0.08411
hash1 := geohashi.EncodeWithPrecision(lat, lon, 10)
fmt.Printf("%d (%d)\n", hash1, hash1.Precision())
hash2 := geohashi.EncodeWithPrecision(lat, lon, 20)
fmt.Printf("%d (%d)\n", hash2, hash2.Precision())
}
```
Decode hash:
```go
func Decode() {
hash := geohashi.Hash(90072520759854475)
area := hash.Decode()
lat, lon := area.Center()
fmt.Printf("%.5f,%.5f\n", lat, lon)
fmt.Println(area.Contains(51.52463, -0.08411))
}
```
## Precision
This library allows you to select the precision of the hash you want to create, up to a maximum of 26 bits.
The following table shows the maximum uncertainty (at the equator) for a given bit-precision:
|Bits| Uncertainty |
|----|-------------|
| 26 | ±0.35m |
| 25 | ±0.65m |
| 24 | ±1.3m |
| 23 | ±2.6m |
| 22 | ±5.3m |
| 21 | ±11m |
| 20 | ±21m |
| 19 | ±42m |
| 18 | ±84m |
| 17 | ±170m |
| 16 | ±340m |
| 15 | ±680m |
| 14 | ±1400m |
| 13 | ±2700m |
| 12 | ±5400m |
| 11 | ±11000m |
| 10 | ±22000m |
| 9 | ±43000m |
| 8 | ±86000m |
| 7 | ±170000m |
| 6 | ±350000m |
| 5 | ±690000m |
| 4 | ±1400000m |
| 3 | ±2800000m |
| 2 | ±5400000m |
| 1 | ±10000000m |