0

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.

2 Answers 2

0

The API for GPS used on Ubuntu Touch is standard QtLocation API. You can use it from C++ or QML.

2
  • I think their question is if there's a Go-accessible API for this? You don't happen to know if there is or not do you?
    – Thomas Ward
    Aug 12, 2019 at 14:10
  • 1
    From Go, you would need to call into the C++ to use 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.
    – dobey
    Aug 12, 2019 at 14:52
0

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)
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .