geohash

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 2 Imported by: 8

README

Geohash

A geohash library for Go (Golang)

Go Reference

Features

  • Encode latitude/longitude to geohash
  • Decode geohash to latitude/longitude
  • Round a geohash box to a single location
  • Commande-line tool

Documentation

Overview

Package geohash provides an implementation of geohash.

http://en.wikipedia.com/wiki/Geohash

http://geohash.org

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(lat, lon float64, precision int) string

Encode encodes a location to a geohash.

The maximum supported precision is 32.

func EncodeAuto

func EncodeAuto(lat, lon float64) string

EncodeAuto encodes a location to a geohash using the most suitable precision.

Types

type Box

type Box struct {
	Lat, Lon Range
}

Box is a spatial data structure.

It is defined by 2 ranges of latitude/longitude.

func Decode

func Decode(gh string) (Box, error)

Decode decode a geohash to a Box.

func (Box) Center

func (b Box) Center() Point

Center returns the Box's center as a Point.

func (Box) Round

func (b Box) Round() Point

Round returns the Box's approximate location as a Point.

It uses decimal rounding and is in general more useful than Center.

type Neighbors

type Neighbors struct {
	North     string
	NorthEast string
	East      string
	SouthEast string
	South     string
	SouthWest string
	West      string
	NorthWest string
}

Neighbors will contain the geohashes for the neighbors of the supplied geohash in each of the cardinal and intercardinal directions.

func GetNeighbors

func GetNeighbors(gh string) (Neighbors, error)

GetNeighbors returns a struct representing the Neighbors of the supplied geohash in each of the cardinal and intercardinal directions.

type Point

type Point struct {
	Lat, Lon float64
}

Point represents a location (latitude and longitude).

type Range

type Range struct {
	Min, Max float64
}

Range represents a range (min/max) on latitude or longitude.

func (Range) Mid

func (r Range) Mid() float64

Mid return the middle value between Min and Max.

func (Range) Round

func (r Range) Round() float64

Round returns the rounded value between Min and Max.

It uses decimal rounding.

func (Range) Val

func (r Range) Val() float64

Val returns the difference between Min and Max.

Directories

Path Synopsis
cmd
geohash
Geohash command-line.
Geohash command-line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL