geocode

package module
Version: v0.0.0-...-c32c2d9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: MIT Imports: 11 Imported by: 2

README

Geocode

Package geocode is a simple geocoding package.

GoDoc

Documentation

Overview

Package geocode is a simple interface to github.com/kellydunn/golang-geo.

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")

ErrCacheMiss is returned by Cache.Load when a query string is not cached yet.

Functions

func EnableLogging

func EnableLogging(w io.Writer)

EnableLogging enables error logging on w.

Types

type Geocoder

type Geocoder interface {
	Geocode(query string) (Result, error)
	Close() error
}

Geocoder looks up geographical locations.

func Cache

func Cache(gc Geocoder, qc QueryCache) Geocoder

Cache returns a geocoder that caches results from gc.

func Delay

func Delay(gc Geocoder, d time.Duration) Geocoder

Delay returns a Geocoder that delays requests sent to gc.

It ensures requests are at least d apart.

func Google

func Google(apikey string) Geocoder

Google returns a geocoder using the Google geocode API.

The apikey argument may be empty.

func LatLong

func LatLong(gc Geocoder) Geocoder

LatLong returns a geocoder that simply decodes strings with latitude and longitude values.

It calls gc when not nil and it cannot decode the latitude and longitude.

func OpenLocationCode

func OpenLocationCode(gc Geocoder) Geocoder

OpenLocationCode returns a Geocoder that understands Open Location Codes.

It uses gc to find the reference of short open location codes, and to decode query strings that are not location codes.

func StdGoogle

func StdGoogle(apikey string) Geocoder

StdGoogle returns a geocoder using delayed calls to the Google geocode API.

The apikey argument may be empty.

type QueryCache

type QueryCache interface {
	Load(query string) (Result, error)
	Store(query string, res Result, err error) error

	Close() error
}

QueryCache caches geocode results.

func LevelDB

func LevelDB(path string) (QueryCache, error)

LevelDB returns a QueryCache stored at path.

func Memory

func Memory() QueryCache

Memory returns a new Cache backed by process memory.

type Result

type Result struct {
	// Lat, Long is the most relevant position (when available)
	// or the centre of the boundary rectangle.
	Lat, Long float64

	// boundary rectangle
	North float64
	East  float64
	South float64
	West  float64
}

Result is a geocode result.

func (Result) Center

func (r Result) Center() (lat, long float64)

Center returns the center of the boundary rectangle in r.

func (Result) EmptyArea

func (r Result) EmptyArea() bool

EmptyArea reports if r has zero area.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL