Documentation ¶
Overview ¶
Package geolocation provides a convenient idiomatic wrapper for the browser geolocation API.
Index ¶
Constants ¶
const ( // ErrUnknown will be returned if the value is not supplied by // the implementation. ErrUnknown = Error("value unknown") // ErrStationary will be returned if the device velocity is // requested when the device is stationary. ErrStationary = Error("device stationary") )
const ( // ErrPermissionDenied will be returned if the location // acquisition process failed because the document does // not have permission to use the Geolocation API. ErrPermissionDenied = Error("permission denied") // of the device could not be determined. For instance, one // or more of the location providers used in the location // acquisition process reported an internal error that // caused the process to fail entirely. ErrPositionUnavailable = Error("position unavailable") // ErrTimeout will be returned if the length of time // specified by the Timeout property has elapsed before // the implementation could successfully acquire a new // GeolocationPosition object. ErrTimeout = Error("timeout") )
const ( // ErrWatcherClosed will be returned from Next if the watcher is closed. ErrWatcherClosed = Error("watcher closed") )
Variables ¶
This section is empty.
Functions ¶
func CurrentPosition ¶
func CurrentPosition(options *PositionOptions) (*Position, *Error)
CurrentPosition requests the location of the device.
Types ¶
type Coords ¶
type Coords struct { // Latitude and Longitude are geographic coordinates // specified in decimal degrees. Latitude float64 Longitude float64 // Accuracy denotes the accuracy level of the latitude and // longitude coordinates in meters. Accuracy float64 // contains filtered or unexported fields }
Coords represents a place on Earth. The geographic coordinate reference system used is the World Geodetic System (2d) [WGS84].
func (*Coords) Altitude ¶
Altitude denotes the height of the position, specified in meters above the [WGS84] ellipsoid. Altitude may not be avilable on all platforms at all times. ErrUnknown will be returned, if the altitude is not known or unsupported by the host device.
func (*Coords) AltitudeAccuracy ¶
AltitudeAccuracy is specified in meters. This may return an ErrUnknown error if the accuracy is unavailable og unsupported on the host device.
func (*Coords) Heading ¶
Heading is the direction of travel of the device and is specified in degrees, where 0° ≤ Heading < 360°, counting clockwise relative to the true north. If this is unknown or unsupported, it will return an ErrUnknown error. If the host device is not moving, it will return ErrStationary.
type Error ¶
type Error string
Error is an error type specific for this package. It satisfiers the error interface so you may pass it along as a regular error.
type Position ¶
type Position struct { Coords *Coords // Timestamp is the acquisition time of the position. Timestamp time.Time }
Position is a container for the geolocation information.
type PositionOptions ¶
type PositionOptions struct { // HighAccuracy provides a hint that the application would like // to receive the best possible results. This may result in // slower response times or increased power consumption. The // user might also deny this capability, or the device might // not be able to provide more accurate results than if the // flag wasn't specified. HighAccuracy bool // Timeout denotes the maximum length of time that is allowed // to pass until a position or an error is returned. Timeout time.Duration // MaximumAge indicates that the application is willing to // accept a cached position whose age is no greater than the // specified time. MaximumAge time.Duration }
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher provides a convenient interface for watching the device position.
func WatchPosition ¶
func WatchPosition(options *PositionOptions) *Watcher
WatchPosition will continually watch the device position.
func (Watcher) Chans ¶
Chans returns two channels. One carrying location updates, and the other carrying errors. This is useful for getting updates in a select loop.