location

package
v0.0.0-...-0dfd57a Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Service location stores the user location and provides automatic checkins and geocoding.

Index

Constants

View Source
const API_URL = "https://nominatim.openstreetmap.org"

Variables

View Source
var (
	ErrWrongNumberOfCols = errors.New("Number of fields and columns differs")
	ErrNoTimestamp       = errors.New("No time found")
	ErrNoLatLng          = errors.New("No latitude or longitude found")
)
View Source
var Module = &services.Module{
	Name:        "location",
	Version:     "1.0",
	NewInstance: NewService,
}
View Source
var MsgAddressNotFound = sarif.Message{
	Action: "err/location/address/notfound",
	Text:   "Requested address could not be found",
}
View Source
var MsgNotFound = sarif.Message{
	Action: "err/location/notfound",
	Text:   "No matching location found.",
}

Functions

func EncodeGeohash

func EncodeGeohash(latitude, longitude float64, precision int) string

func HaversineDistance

func HaversineDistance(p1, p2 Location) float64

Types

type BoundingBox

type BoundingBox struct {
	LatMin float64 `json:"lat_min"`
	LatMax float64 `json:"lat_max"`
	LngMin float64 `json:"lng_min"`
	LngMax float64 `json:"lng_max"`
}

func DecodeGeohash

func DecodeGeohash(geohash string) *BoundingBox

func (*BoundingBox) Contains

func (b *BoundingBox) Contains(loc Location) bool

func (*BoundingBox) GetBounds

func (g *BoundingBox) GetBounds() []float64

func (*BoundingBox) SetBounds

func (g *BoundingBox) SetBounds(b []float64)

type BoundingBoxSlice

type BoundingBoxSlice BoundingBox

func (*BoundingBoxSlice) UnmarshalJSON

func (b *BoundingBoxSlice) UnmarshalJSON(j []byte) (err error)

type Cluster

type Cluster struct {
	Location
	Status ClusterStatus `json:"status"`

	Start Location `json:"start,omitempty"`
	End   Location `json:"end,omitempty"`
}

func (Cluster) Text

func (c Cluster) Text() string

type ClusterGenerator

type ClusterGenerator struct {
	MinInterval time.Duration
	MaxDistance float64
	// contains filtered or unexported fields
}

func NewClusterGenerator

func NewClusterGenerator() *ClusterGenerator

func (*ClusterGenerator) Advance

func (g *ClusterGenerator) Advance(l Location) bool

func (*ClusterGenerator) ClearCompleted

func (g *ClusterGenerator) ClearCompleted()

func (*ClusterGenerator) Completed

func (g *ClusterGenerator) Completed() []Cluster

func (*ClusterGenerator) Current

func (g *ClusterGenerator) Current() Cluster

func (*ClusterGenerator) LastCompleted

func (g *ClusterGenerator) LastCompleted() Cluster

type ClusterStatus

type ClusterStatus int
const (
	UnconfirmedCluster ClusterStatus = iota
	ConfirmedCluster
	CompletedCluster
)

type Dependencies

type Dependencies struct {
	Client sarif.Client
}

type GeoAddress

type GeoAddress struct {
	HouseNumber  string `json:"house_number"`
	Building     string `json:"building"`
	Road         string `json:"road"`
	Residential  string `json:"residential"`
	Suburb       string `json:"suburb"`
	Village      string `json:"village"`
	Town         string `json:"town"`
	CityDistrict string `json:"city_district"`
	City         string `json:"city"`
	County       string `json:"county"`
	PostCode     string `json:"postcode"`
	State        string `json:"state"`
	Country      string `json:"country"`
	CountryCode  string `json:"country_code"`
	Continent    string `json:"continent"`
}

type GeoName

type GeoName struct {
	Name string `json:"name,omitempty"`
}

type GeoPlace

type GeoPlace struct {
	BoundingBox BoundingBoxSlice `json:"boundingbox,[]string"`
	Latitude    float64          `json:"lat,string"`
	Longitude   float64          `json:"lon,string"`
	Name        string           `json:"display_name"`
	Class       string           `json:"class"`
	Type        string           `json:"type"`
	Address     GeoAddress       `json:"address"`
	NameDetails GeoName          `json:"namedetails,omitempty"`
}

func Geocode

func Geocode(query string) ([]GeoPlace, error)

func ReverseGeocode

func ReverseGeocode(loc Location) (GeoPlace, error)

func (GeoPlace) Pretty

func (p GeoPlace) Pretty() string

type Geofence

type Geofence struct {
	BoundingBox
	Name       string `json:"name,omitempty"`
	Address    string `json:"address,omitempty"`
	GeohashMin string `json:"geohash_min,omitempty"`
	GeohashMax string `json:"geohash_max,omitempty"`
}

func (Geofence) Key

func (g Geofence) Key() string

type GeofenceEventPayload

type GeofenceEventPayload struct {
	Location Location `json:"loc"`
	Fence    Geofence `json:"fence"`
	Status   string   `json:"status"`
}

func (GeofenceEventPayload) String

func (m GeofenceEventPayload) String() string

type Location

type Location struct {
	Time      time.Time `json:"time,omitempty"`
	Latitude  float64   `json:"latitude"`
	Longitude float64   `json:"longitude"`
	Geohash   string    `json:"geohash,omitempty"`
	Accuracy  float64   `json:"accuracy"`
	Source    string    `json:"source,omitempty"`
	Address   string    `json:"address,omitempty"`

	Distance float64 `json:"distance,omitempty"`
	Speed    float64 `json:"speed,omitempty"`
}

func ReadCSV

func ReadCSV(r io.Reader) ([]*Location, error)

func (Location) Key

func (loc Location) Key() string

func (Location) String

func (l Location) String() string

type Service

type Service struct {
	sarif.Client
	Store *store.Store

	Clusters *ClusterGenerator
}

func NewService

func NewService(deps *Dependencies) *Service

func (*Service) Enable

func (s *Service) Enable() error

Jump to

Keyboard shortcuts

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