-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_gpx.go
50 lines (46 loc) · 1.18 KB
/
writer_gpx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bufio"
"io"
"text/template"
)
const (
gpxHeader = `<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="Google Latitude JSON Converter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<name>Location History</name>
</metadata>
<trk>
<trkseg>`
gpxLocTemplate = `
<trkpt lat="{{ .LatitudeE7 | e7todec }}" lon="{{ .LongitudeE7 | e7todec }}">
<time>{{ .Timestamp }}</time>
<accuracy>{{ .Accuracy }}</accuracy>
</trkpt>`
gpxNewTrack = `
</trkseg>
</trk>
<trk>
<trkseg>`
gpxNewSegment = `
</trkseg>
<trkseg>`
gpxFooter = `
</trkseg>
</trk>
</gpx>
`
)
func NewGPXWriter(w io.Writer) Writer {
// compile the templates
locTemplate := template.New("gpx").Funcs(funcMap)
locTemplate = template.Must(locTemplate.Parse(gpxLocTemplate))
return &TemplateWriter{
w: bufio.NewWriter(w),
header: gpxHeader,
location: locTemplate,
newSegment: gpxNewSegment,
newTrack: gpxNewTrack,
footer: gpxFooter,
}
}