-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_kml.go
39 lines (35 loc) · 912 Bytes
/
writer_kml.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
package main
import (
"bufio"
"io"
"text/template"
)
const (
kmlHeader = `<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Location History</name>`
kmlLocTemplate = `
<Placemark>
<TimeStamp><when>{{ .Timestamp }}</when></TimeStamp>
<ExtendedData>
<Data name="accuracy"><value>{{ .Accuracy }}</value></Data>
</ExtendedData>
<Point><coordinates>{{ .LongitudeE7 | e7todec }},{{ .LatitudeE7 | e7todec }}</coordinates></Point>
</Placemark>`
kmlFooter = `
</Document>
</kml>
`
)
func NewKMLWriter(w io.Writer) Writer {
// compile the templates
locTemplate := template.New("kml").Funcs(funcMap)
locTemplate = template.Must(locTemplate.Parse(kmlLocTemplate))
return &TemplateWriter{
w: bufio.NewWriter(w),
header: kmlHeader,
location: locTemplate,
footer: kmlFooter,
}
}