Use nmea.Parse(sentence) to parse standard NMEA sentences. The function returns a nmea.Sentence interface. To access specific fields, check the sentence type using s.DataType() and then perform a type assertion to the corresponding message struct (e.g., nmea.RMC).
For coordinate formatting, use nmea.FormatGPS(value) for decimal degrees and nmea.FormatDMS(value) for Degrees, Minutes, Seconds format.
package main
import (
"fmt"
"log"
"github.com/adrianmo/go-nmea"
)
func main() {
sentence := "$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70"
s, err := nmea.Parse(sentence)
if err != nil {
log.Fatal(err)
}
if s.DataType() == nmea.TypeRMC {
m := s.(nmea.RMC)
fmt.Printf("Time: %s\n", m.Time)
fmt.Printf("Latitude GPS: %s\n", nmea.FormatGPS(m.Latitude))
fmt.Printf("Latitude DMS: %s\n", nmea.FormatDMS(m.Latitude))
}
}