Documentation ¶
Overview ¶
Package geohash provides encoding and decoding of string and integer geohashes.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { // Uluru in Australian Outback lat, lng := -25.345457, 131.036192 // Encode a full 12 character string geohash fmt.Println(geohash.Encode(lat, lng)) // Or at lower precision fmt.Println(geohash.EncodeWithPrecision(lat, lng, 6)) // As an integer fmt.Printf("%016x\n", geohash.EncodeInt(lat, lng)) // Decode to a point fmt.Println(geohash.Decode("qgmpvf18")) // or to a bounding box fmt.Println(geohash.BoundingBox("qgmpvf18")) }
Output: qgmpvf18h86e qgmpvf b3e75db828820cd5 -25.3454 131.036 {-25.345458984375 -25.345287322998047 131.03599548339844 131.03633880615234}
Index ¶
- func ConvertIntToString(hash uint64, chars uint) string
- func ConvertStringToInt(hash string) (uint64, uint)
- func Decode(hash string) (lat, lng float64)
- func DecodeCenter(hash string) (lat, lng float64)
- func DecodeInt(hash uint64) (lat, lng float64)
- func DecodeIntWithPrecision(hash uint64, bits uint) (lat, lng float64)
- func Encode(lat, lng float64) string
- func EncodeInt(lat, lng float64) uint64
- func EncodeIntWithPrecision(lat, lng float64, bits uint) uint64
- func EncodeWithPrecision(lat, lng float64, chars uint) string
- func Neighbor(hash string, direction Direction) string
- func NeighborInt(hash uint64, direction Direction) uint64
- func NeighborIntWithPrecision(hash uint64, bits uint, direction Direction) uint64
- func Neighbors(hash string) []string
- func NeighborsInt(hash uint64) []uint64
- func NeighborsIntWithPrecision(hash uint64, bits uint) []uint64
- func Validate(hash string) error
- type Box
- type Direction
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertIntToString ¶ added in v0.10.0
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 ¶ added in v0.10.0
ConvertStringToInt converts a string geohash to the equivalent integer geohash. Returns the integer hash and its precision.
func Decode ¶
Decode the string geohash to a (lat, lng) point.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { lat, lng := geohash.Decode("u09tunq6") fmt.Printf("%.3f %.3f\n", lat, lng) }
Output: 48.858 2.294
func DecodeCenter ¶
DecodeCenter decodes the string geohash to the central point of the bounding box.
func DecodeInt ¶
DecodeInt decodes the provided 64-bit integer geohash to a (lat, lng) point.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { lat, lng := geohash.DecodeInt(0xd0139d52c6b54c69) fmt.Printf("%.3f %.3f\n", lat, lng) }
Output: 48.858 2.294
func DecodeIntWithPrecision ¶
DecodeIntWithPrecision decodes the provided integer geohash with bits of precision to a (lat, lng) point.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { lat, lng := geohash.DecodeIntWithPrecision(0xd013, uint(16)) fmt.Printf("%.3f %.3f\n", lat, lng) }
Output: 48.600 2.000
func Encode ¶
Encode the point (lat, lng) as a string geohash with the standard 12 characters of precision.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { fmt.Println(geohash.Encode(48.858, 2.294)) }
Output: u09tunq6qp66
func EncodeInt ¶
EncodeInt encodes the point (lat, lng) to a 64-bit integer geohash.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { fmt.Printf("%016x\n", geohash.EncodeInt(48.858, 2.294)) }
Output: d0139d52c6b54c69
func EncodeIntWithPrecision ¶
EncodeIntWithPrecision encodes the point (lat, lng) to an integer with the specified number of bits.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { fmt.Printf("%08x\n", geohash.EncodeIntWithPrecision(48.858, 2.294, 32)) }
Output: d0139d52
func EncodeWithPrecision ¶
EncodeWithPrecision encodes the point (lat, lng) as a string geohash with the specified number of characters of precision (max 12).
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/geohash" ) func main() { fmt.Println(geohash.EncodeWithPrecision(48.858, 2.294, 5)) }
Output: u09tu
func Neighbor ¶
Neighbor returns a geohash string that corresponds to the provided geohash's neighbor in the provided direction
func NeighborInt ¶
NeighborInt returns a uint64 that corresponds to the provided hash's neighbor in the provided direction at 64-bit precision.
func NeighborIntWithPrecision ¶
NeighborIntWithPrecision returns a uint64s that corresponds to the provided hash's neighbor in the provided direction at the given precision.
func Neighbors ¶
Neighbors returns a slice of geohash strings that correspond to the provided geohash's neighbors.
func NeighborsInt ¶
NeighborsInt returns a slice of uint64s that correspond to the provided hash's neighbors at 64-bit precision.
func NeighborsIntWithPrecision ¶
NeighborsIntWithPrecision returns a slice of uint64s that correspond to the provided hash's neighbors at the given precision.
Types ¶
type Box ¶
Box represents a rectangle in latitude/longitude space.
func BoundingBox ¶
BoundingBox returns the region encoded by the given string geohash.
func BoundingBoxInt ¶
BoundingBoxInt returns the region encoded by the given 64-bit integer geohash.
func BoundingBoxIntWithPrecision ¶
BoundingBoxIntWithPrecision returns the region encoded by the integer geohash with the specified precision.