geoclue2

package module
v0.0.0-...-1b715b5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

A Go library for Geoclue2

Status

Geoclue2 is a DBus service for providing geolocation services. This is a Go library for making it easy to get location information via Geoclue2.

Install

Use go get github.com/ldx/go-geoclue2.

Usage

A simple workflow for starting the service, waiting for one location update, and then stopping the service:

// Connect to DBus.
conn, err := dbus.SystemBus()
if err != nil {
	panic(err)
}
defer conn.Close()
// Start service and wait for location.
gc2 := geoclue2.NewGeoClue2(conn, "")
gc2.Start()
loc, err := gc2.WaitForLocation(context.Background())
if err != nil {
	panic(err)
}
fmt.Printf("location update: %+v\n", j, loc)
// Stop service.
gc2.Stop()

There are more examples in examples/.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbusConn

type DbusConn interface {
	Signal(ch chan<- *dbus.Signal)
	Object(iface string, path dbus.ObjectPath) dbus.BusObject
}

type GeoClue2

type GeoClue2 struct {
	// contains filtered or unexported fields
}

GeoClue2 is used for receiving location information from the geoclue2 service.

func NewGeoClue2

func NewGeoClue2(conn *dbus.Conn, desktopID string) *GeoClue2

NewGeoClue2 is used to create a new GeoClue2 struct.

func (*GeoClue2) GetLatestLocation

func (g *GeoClue2) GetLatestLocation() *Location

GetLatestLocation returns the last location received from geoclue2.

func (*GeoClue2) Start

func (g *GeoClue2) Start()

Start starts the main loop that receives and distributes location updates.

func (*GeoClue2) Stop

func (g *GeoClue2) Stop()

Stop stops the main loop and waits until it has shut down.

func (*GeoClue2) WaitForLocation

func (g *GeoClue2) WaitForLocation(ctx context.Context) (*Location, error)

WaitForLocation waits for the next location update.

type Location

type Location struct {
	// The latitude of the location, in degrees.
	Latitude float64 `dbus:"Latitude"`
	// The longitude of the location, in degrees.
	Longitude float64 `dbus:"Longitude"`
	// The accuracy of the location fix, in meters.
	Accuracy float64 `dbus:"Accuracy"`
	// The altitude of the location fix, in meters. When unknown, its set to
	// minimum double value, -1.7976931348623157e+308.
	Altitude float64 `dbus:"Altitude"`
	// The speed in meters per second. When unknown, it's set to -1.0.
	Speed float64 `dbus:"Speed"`
	// The heading direction in degrees with respect to North direction, in
	// clockwise order. That means North becomes 0 degree, East: 90 degrees,
	// South: 180 degrees, West: 270 degrees and so on. When unknown, it's set
	// to -1.0.
	Heading float64 `dbus:"Heading"`
	// A human-readable description of the location, if available.
	// WARNING: Applications should not rely on this property since not all
	// sources provide a description. If you really need a description (or more
	// details) about current location, use a reverse-geocoding API, e.g
	// geocode-glib.
	Description string `dbus:"Description"`
	// The timestamp when the location was determined, in seconds and
	// microseconds since the Epoch. This is the time of measurement if the
	// backend provided that information, otherwise the time when GeoClue
	// received the new location. Note that GeoClue can't guarantee that the
	// timestamp will always monotonically increase, as a backend may not
	// respect that. Also note that a timestamp can be very old, e.g. because
	// of a cached location.
	Timestamp Timestamp `dbus:"Timestamp"`
}

Location contains location information returned by geoclue2.

type MockBusObject

type MockBusObject struct {
	DoCall              func(method string, flags dbus.Flags, args ...interface{}) *dbus.Call
	DoCallWithContext   func(ctx context.Context, method string, flags dbus.Flags, args ...interface{}) *dbus.Call
	DoGo                func(method string, flags dbus.Flags, ch chan *dbus.Call, args ...interface{}) *dbus.Call
	DoGoWithContext     func(ctx context.Context, method string, flags dbus.Flags, ch chan *dbus.Call, args ...interface{}) *dbus.Call
	DoAddMatchSignal    func(iface, member string, options ...dbus.MatchOption) *dbus.Call
	DoRemoveMatchSignal func(iface, member string, options ...dbus.MatchOption) *dbus.Call
	DoGetProperty       func(p string) (dbus.Variant, error)
	DoSetProperty       func(p string, v interface{}) error
	DoDestination       func() string
	DoPath              func() dbus.ObjectPath
}

func (*MockBusObject) AddMatchSignal

func (o *MockBusObject) AddMatchSignal(iface, member string, options ...dbus.MatchOption) *dbus.Call

func (*MockBusObject) Call

func (o *MockBusObject) Call(method string, flags dbus.Flags, args ...interface{}) *dbus.Call

func (*MockBusObject) CallWithContext

func (o *MockBusObject) CallWithContext(ctx context.Context, method string, flags dbus.Flags, args ...interface{}) *dbus.Call

func (*MockBusObject) Destination

func (o *MockBusObject) Destination() string

func (*MockBusObject) GetProperty

func (o *MockBusObject) GetProperty(p string) (dbus.Variant, error)

func (*MockBusObject) Go

func (o *MockBusObject) Go(method string, flags dbus.Flags, ch chan *dbus.Call, args ...interface{}) *dbus.Call

func (*MockBusObject) GoWithContext

func (o *MockBusObject) GoWithContext(ctx context.Context, method string, flags dbus.Flags, ch chan *dbus.Call, args ...interface{}) *dbus.Call

func (*MockBusObject) Path

func (o *MockBusObject) Path() dbus.ObjectPath

func (*MockBusObject) RemoveMatchSignal

func (o *MockBusObject) RemoveMatchSignal(iface, member string, options ...dbus.MatchOption) *dbus.Call

func (*MockBusObject) SetProperty

func (o *MockBusObject) SetProperty(p string, v interface{}) error

type MockDbusConn

type MockDbusConn struct {
	DoSignal func(ch chan<- *dbus.Signal)
	DoObject func(iface string, path dbus.ObjectPath) dbus.BusObject
}

func (*MockDbusConn) Object

func (d *MockDbusConn) Object(iface string, path dbus.ObjectPath) dbus.BusObject

func (*MockDbusConn) Signal

func (d *MockDbusConn) Signal(ch chan<- *dbus.Signal)

type RealDbusConn

type RealDbusConn struct {
	// contains filtered or unexported fields
}

func (*RealDbusConn) Object

func (d *RealDbusConn) Object(iface string, path dbus.ObjectPath) dbus.BusObject

func (*RealDbusConn) Signal

func (d *RealDbusConn) Signal(ch chan<- *dbus.Signal)

type Timestamp

type Timestamp struct {
	// Seconds since the Epoch.
	Seconds uint64
	// Microseconds.
	Microseconds uint64
}

The timestamp when the location was determined, in seconds and microseconds since the Epoch.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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