Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active June 12, 2021 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zulhfreelancer/23847fadd50b2a16c6baea45767da5b1 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/23847fadd50b2a16c6baea45767da5b1 to your computer and use it in GitHub Desktop.
Get latitude and longitude from Glonass GPS USB stick (U-blox7) using Golang
package main
import (
"fmt"
"github.com/stratoberry/go-gpsd"
"time"
)
func main() {
var gps *gpsd.Session
var err error
fmt.Println("Dialing...")
if gps, err = gpsd.Dial(gpsd.DefaultAddress); err != nil {
panic(fmt.Sprintf("Failed to connect to GPSD: %s", err))
}
fmt.Println("Adding filter...")
gps.AddFilter("TPV", func(r interface{}) {
tpv := r.(*gpsd.TPVReport)
fmt.Println("Lat", tpv.Lat, "Lon", tpv.Lon)
time.Sleep(5 * time.Second)
})
fmt.Println("Watching for location data...")
done := gps.Watch()
<-done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment