Skip to content

location ​

go
import "github.com/tangoui/tango/sys/location"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

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.

常量 ​

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

变量 ​

go
var (
	ErrUnsupported      = platform.ErrUnsupported
	ErrNotAvailable     = platform.ErrNotAvailable
	ErrPermissionDenied = platform.ErrPermissionDenied
	ErrNotConfigured    = platform.ErrNotConfigured
)

函数 ​

func Watch ​

go
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.

类型 ​

Accuracy ​

go
type Accuracy = platform.LocationAccuracy

Accuracy trades precision for battery.

Location ​

go
type Location = platform.Location

Location is one fix.

func Current ​

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

Current returns one fix.

Options ​

go
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.

以 MIT 许可发布