I want to develop a ubuntu touch app that show the currently gps coordinates. What is the best way to get access to the GPS position with go? I could not find any documentation for that.
Thank you.
The API for GPS used on Ubuntu Touch is standard QtLocation API. You can use it from C++ or QML.
QtLocation
. As Go is designed for one-off microservices to quickly deploy on servers with no dependencies, it's really not a good choice for building end user graphical applications, unfortunately.
There is a quite easy way to get the GPS-position using the ubuntu-location-serviced daemon, continuously sending notifications to the DBUS.
Enter
sudo dbus-monitor --system "type='method_call',member='UpdatePosition',interface='com.ubuntu.location.Service.Session'"
on command line.
The code in Go might look like this:
package main
import (
"fmt"
"os"
"github.com/godbus/dbus/v5"
)
func main() {
conn, err := dbus.ConnectSystemBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
os.Exit(1)
}
defer conn.Close()
var rules = []string{
"type='method_call',member='UpdatePosition',interface='com.ubuntu.location.Service.Session'",
}
var flag uint = 0
call := conn.BusObject().Call("org.freedesktop.DBus.Monitoring.BecomeMonitor", 0, rules, flag)
if call.Err != nil {
fmt.Fprintln(os.Stderr, "Failed to become monitor:", call.Err)
os.Exit(1)
}
c := make(chan *dbus.Message, 10)
conn.Eavesdrop(c)
fmt.Println("Monitoring notifications")
for v := range c {
fmt.Println(v)
}
}