Gets the current device location using GPS or network providers.
Usage #
package main
import (
"fmt"
t "github.com/hugmouse/gotermux"
)
func main() {
locationRequest := t.TLocation{
Provider: "gps",
Request: "once",
}
location := t.TermuxLocation(locationRequest)
fmt.Printf("Latitude: %f, Longitude: %f\n",
location.Latitude, location.Longitude)
fmt.Printf("Accuracy: %f meters\n", location.Accuracy)
}
Output:
Latitude: 37.4219999, Longitude: -122.0840575
Accuracy: 10.0 meters
Parameters #
location TLocation
- Location request configuration
Struct TLocation #
Field | Type | Description |
---|---|---|
Provider | string | Location provider (“gps”, “network”, etc.) |
Request | string | Request type (“once”, “updates”, etc.) |
Return Value #
Returns TLocationResult
containing location information.
Struct TLocationResult #
Field | Type | Description |
---|---|---|
Latitude | float64 | Latitude coordinate |
Longitude | float64 | Longitude coordinate |
Altitude | float64 | Altitude in meters |
Accuracy | float64 | Location accuracy in meters |
Bearing | float64 | Direction of travel in degrees |
Speed | float64 | Speed in meters per second |
Timestamp | int64 | Unix timestamp of location fix |
Provider | string | Provider used for location |
Location Providers #
gps
- GPS satellite positioning (more accurate, requires clear sky)network
- Network-based positioning (faster, works indoors)passive
- Use cached location from other apps
Request Types #
once
- Get location once and returnupdates
- Get continuous location updates
Location access requires appropriate permissions. The device may prompt for location permission when first used.