Last active
June 12, 2021 16:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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