-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoords.go
52 lines (37 loc) · 867 Bytes
/
coords.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
51
52
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"github.com/twpayne/go-polyline"
)
func main() {
exampleEncodeCoords()
}
func exampleEncodeCoords() {
coords := make([][]float64, 0)
archivo, err := os.Open("example.txt")
if err != nil {
fmt.Println(err)
}
defer archivo.Close()
scanner := bufio.NewScanner(archivo)
count := 0
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "Location arrived") {
result := strings.Fields(line)
coords = append(coords, make([]float64, 0))
rst := result[9]
latitud, _ := strconv.ParseFloat(rst[2:13], 64)
longitud, _ := strconv.ParseFloat(rst[14:26], 64)
coords[count] = append(coords[count], latitud)
coords[count] = append(coords[count], longitud)
count++
}
}
polilinea := polyline.EncodeCoords(coords)
fmt.Printf("%s\n", polilinea)
}