geofencing

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 geofencing notices when the phone enters or leaves a place, even while the app is in the background. Events wait on the phone until the app asks for them.

nimbus native plugin add geofencing

geofencing.Request(ctx)
geofencing.Add(ctx, geofencing.Region{ID: "cafe", Latitude: 18.53, Longitude: 73.89, Radius: 150})
go geofencing.Watch(ctx, func(e geofencing.Event) { greet(e) })

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(ctx context.Context, r Region) error

Add starts watching a region. iOS allows 20 at a time.

func Remove

func Remove(ctx context.Context, id string) error

Remove stops watching a region.

func Request

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

Request asks to watch the location in the background. Both platforms ask in two steps, and may send the person to Settings for the second.

func Watch

func Watch(ctx context.Context, f func(Event)) error

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

Types

type Event

type Event struct {
	ID    string    `json:"id"`    // the Region's ID
	Enter bool      `json:"enter"` // false: left
	At    time.Time `json:"-"`     // when it happened
	Time  float64   `json:"time"`  // seconds since 1970
}

Event is a crossing of a Region's edge.

func Events

func Events(ctx context.Context) ([]Event, error)

Events returns what has happened since the last call.

type Region

type Region struct {
	ID        string  `json:"id"`        // your name for it
	Latitude  float64 `json:"latitude"`  // of the middle, in degrees
	Longitude float64 `json:"longitude"` // of the middle, in degrees
	Radius    float64 `json:"radius"`    // metres
}

Region is a circle on the map. Below about 100 metres it's unreliable.

Jump to

Keyboard shortcuts

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