backgroundlocation

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package backgroundlocation keeps following the phone after the person leaves your app: a delivery, a run, a trip. It runs where they can see it, with a notification on Android and the location indicator on iOS, so it needs no "always allow" permission. Start it from a screen on show.

nimbus native plugin add background-location

if ok, _ := backgroundlocation.Request(ctx); ok {
	backgroundlocation.Start(ctx, backgroundlocation.Options{Title: "Trip running", MinDistance: 25})
}
points, err := backgroundlocation.Points(ctx)
backgroundlocation.Stop(ctx)

To notice when someone arrives somewhere, geofencing does that with far less battery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Request

func Request(ctx context.Context) (bool, error)

Request asks to use the location, and on Android to show its notification.

func Running

func Running(ctx context.Context) (bool, error)

Running reports whether it's following.

func Start

func Start(ctx context.Context, o Options) error

Start begins following, until Stop. Call it from a screen on show: both systems refuse to begin from the background. Without permission it fails with plugin.Denied.

func Stop

func Stop(ctx context.Context) error

Stop ends it. Points not yet read stay there for Points.

func Watch

func Watch(ctx context.Context, f func([]Point)) error

Watch calls f with new points until ctx ends. It blocks, so run it from a goroutine in an effect.

Types

type Options

type Options struct {
	Title       string  `json:"title,omitempty"`       // Android's notification heading
	Text        string  `json:"text,omitempty"`        // Android's notification text
	MinDistance float64 `json:"minDistance,omitempty"` // metres to move before the next point; 0 means 10
}

Options say how to follow.

type Point

type Point struct {
	Latitude  float64   `json:"latitude"`  // in degrees
	Longitude float64   `json:"longitude"` // in degrees
	Accuracy  float64   `json:"accuracy"`  // metres
	Speed     float64   `json:"speed"`     // metres a second; below 0 when unknown
	At        time.Time `json:"-"`         // when it was there
	Time      float64   `json:"time"`      // the same, in seconds since 1970
}

Point is one place it passed.

func Points

func Points(ctx context.Context) ([]Point, error)

Points gives what's been collected since the last call, oldest first. The phone holds the newest 5,000, in memory, so read them when the app returns.

Jump to

Keyboard shortcuts

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