location

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package location reads the device's location once or continuously (Core Location on iOS, LocationManager on Android — no Google Play services needed).

loc, err := location.Current(a, location.Options{Accuracy: location.High})
stop, err := location.Watch(a, location.Options{}, func(l location.Location, err error) { ... })
defer stop()

Both ask for when-in-use permission first if the user was never asked; ErrPermissionDenied if refused. iOS needs NSLocationWhenInUseUsageDescription (permission "location"; returns ErrNotConfigured without it); Android needs ACCESS_FINE_LOCATION and/or ACCESS_COARSE_LOCATION. ErrNotAvailable means location services are off.

Functions return ErrUnsupported where the backend has no location and tango.ErrNotRunning after the app quit. On Android call Current from a goroutine, not from a main-thread callback.

Index

Constants

View Source
const (
	Balanced = platform.AccuracyBalanced // ~100 m (default)
	High     = platform.AccuracyHigh     // best available, GPS
	Low      = platform.AccuracyLow      // ~kilometres
)

Variables

View Source
var (
	ErrUnsupported      = platform.ErrUnsupported
	ErrNotAvailable     = platform.ErrNotAvailable
	ErrPermissionDenied = platform.ErrPermissionDenied
	ErrNotConfigured    = platform.ErrNotConfigured
)

Functions

func Watch

func Watch(a *tango.App, o Options, fn func(Location, error)) (stop func(), err error)

Watch calls fn on the main thread with every new fix until stop is called. An error passed to fn (permission revoked, services turned off) ends the watch. Several watches share one session with the best accuracy any of them asked for.

Types

type Accuracy

type Accuracy = platform.LocationAccuracy

Accuracy trades precision for battery.

type Location

type Location = platform.Location

Location is one fix.

func Current

func Current(a *tango.App, o Options) (Location, error)

Current returns one fix.

type Options

type Options struct {
	Accuracy Accuracy
	// DistanceFilter (metres): Watch only reports moves at least this far;
	// 0 reports every update.
	DistanceFilter float64
	// contains filtered or unexported fields
}

Options configures a request.

Jump to

Keyboard shortcuts

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