geohash for golang
Go
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 1 commit ahead of gansidui:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
geohash.go
geohash_test.go

README.md

geohash

geohash algorithm: http://en.wikipedia.org/wiki/Geohash

package main

import (
	"fmt"
	"github.com/sillydong/geohash"
)

func main() {
	latitude := 39.92324
	longitude := 116.3906
	precision := 5

	hash, box := geohash.Encode(latitude, longitude, precision)

	fmt.Println(hash)
	fmt.Println(box.MinLat, box.MaxLat, box.MinLng, box.MaxLng)

	neighbors := geohash.GetNeighbors(latitude, longitude, precision)
	for _, hash = range neighbors {
		fmt.Print(hash, " ")
	}
}

water diffusion

As sometimes 9 grids can not get enough data, LoopNeighbors can diffusion like water until you get enough data.

package main

import (
	"fmt"
	"github.com/sillydong/geohash"
)

func main() {
	latitude := 39.92324
	longitude := 116.3906
	precision := 5

	loopneighbors := geohash.LoopNeighbors(latitude, longitude, precision, 3)
	for loop, hashs := range loopneighbors {
		fmt.Printf("loop: %d\n", loop)
		for _, hash := range hashs {
			fmt.Println("\t"+hash)
		}
	}
}

LICENSE

MIT