项目作者: mmcloughlin

项目描述 :
Golang geohash library
高级语言: Go
项目地址: git://github.com/mmcloughlin/geohash.git
创建时间: 2015-07-10T21:21:20Z
项目社区:https://github.com/mmcloughlin/geohash

开源协议:MIT License

下载


geohash

Go geohash library offering encoding
and decoding for string and integer geohashes.

go.dev Reference
Build status
Coverage
Go Report Card

Install

Fetch the package with

  1. go get github.com/mmcloughlin/geohash

And import it into your programs with

  1. import "github.com/mmcloughlin/geohash"

Usage

func ConvertIntToString

  1. func ConvertIntToString(hash uint64, chars uint) string

ConvertIntToString converts an integer geohash to the equivalent string geohash
with chars characters. The provided integer geohash is interpreted to have
5*chars bits of precision.

func ConvertStringToInt

  1. func ConvertStringToInt(hash string) (uint64, uint)

ConvertStringToInt converts a string geohash to the equivalent integer geohash.
Returns the integer hash and its precision.

func Decode

  1. func Decode(hash string) (lat, lng float64)

Decode the string geohash to a (lat, lng) point.

func DecodeCenter

  1. func DecodeCenter(hash string) (lat, lng float64)

DecodeCenter decodes the string geohash to the central point of the bounding
box.

func DecodeInt

  1. func DecodeInt(hash uint64) (lat, lng float64)

DecodeInt decodes the provided 64-bit integer geohash to a (lat, lng) point.

func DecodeIntWithPrecision

  1. func DecodeIntWithPrecision(hash uint64, bits uint) (lat, lng float64)

DecodeIntWithPrecision decodes the provided integer geohash with bits of
precision to a (lat, lng) point.

func Encode

  1. func Encode(lat, lng float64) string

Encode the point (lat, lng) as a string geohash with the standard 12 characters
of precision.

func EncodeInt

  1. func EncodeInt(lat, lng float64) uint64

EncodeInt encodes the point (lat, lng) to a 64-bit integer geohash.

func EncodeIntWithPrecision

  1. func EncodeIntWithPrecision(lat, lng float64, bits uint) uint64

EncodeIntWithPrecision encodes the point (lat, lng) to an integer with the
specified number of bits.

func EncodeWithPrecision

  1. func EncodeWithPrecision(lat, lng float64, chars uint) string

EncodeWithPrecision encodes the point (lat, lng) as a string geohash with the
specified number of characters of precision (max 12).

func Neighbor

  1. func Neighbor(hash string, direction Direction) string

Neighbor returns a geohash string that corresponds to the provided geohash’s
neighbor in the provided direction

func NeighborInt

  1. func NeighborInt(hash uint64, direction Direction) uint64

NeighborInt returns a uint64 that corresponds to the provided hash’s neighbor in
the provided direction at 64-bit precision.

func NeighborIntWithPrecision

  1. func NeighborIntWithPrecision(hash uint64, bits uint, direction Direction) uint64

NeighborIntWithPrecision returns a uint64s that corresponds to the provided
hash’s neighbor in the provided direction at the given precision.

func Neighbors

  1. func Neighbors(hash string) []string

Neighbors returns a slice of geohash strings that correspond to the provided
geohash’s neighbors.

func NeighborsInt

  1. func NeighborsInt(hash uint64) []uint64

NeighborsInt returns a slice of uint64s that correspond to the provided hash’s
neighbors at 64-bit precision.

func NeighborsIntWithPrecision

  1. func NeighborsIntWithPrecision(hash uint64, bits uint) []uint64

NeighborsIntWithPrecision returns a slice of uint64s that correspond to the
provided hash’s neighbors at the given precision.

func Validate

  1. func Validate(hash string) error

Validate the string geohash.

type Box

  1. type Box struct {
  2. MinLat float64
  3. MaxLat float64
  4. MinLng float64
  5. MaxLng float64
  6. }

Box represents a rectangle in latitude/longitude space.

func BoundingBox

  1. func BoundingBox(hash string) Box

BoundingBox returns the region encoded by the given string geohash.

func BoundingBoxInt

  1. func BoundingBoxInt(hash uint64) Box

BoundingBoxInt returns the region encoded by the given 64-bit integer geohash.

func BoundingBoxIntWithPrecision

  1. func BoundingBoxIntWithPrecision(hash uint64, bits uint) Box

BoundingBoxIntWithPrecision returns the region encoded by the integer geohash
with the specified precision.

func (Box) Center

  1. func (b Box) Center() (lat, lng float64)

Center returns the center of the box.

func (Box) Contains

  1. func (b Box) Contains(lat, lng float64) bool

Contains decides whether (lat, lng) is contained in the box. The containment
test is inclusive of the edges and corners.

func (Box) Round

  1. func (b Box) Round() (lat, lng float64)

Round returns a point inside the box, making an effort to round to minimal
precision.

type Direction

  1. type Direction int

Direction represents directions in the latitute/longitude space.

  1. const (
  2. North Direction = iota
  3. NorthEast
  4. East
  5. SouthEast
  6. South
  7. SouthWest
  8. West
  9. NorthWest
  10. )

Cardinal and intercardinal directions