first commit
This commit is contained in:
commit
2eed16376f
4 changed files with 107 additions and 0 deletions
75
main.go
Normal file
75
main.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/golang-io/requests"
|
||||
"github.com/tkrajina/gpxgo/gpx"
|
||||
)
|
||||
|
||||
type SuisseMobileGeometry struct {
|
||||
Segments [][][]float64 `json:"coordinates"`
|
||||
}
|
||||
|
||||
type SuisseMobileProperties struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type SuisseMobileResponse struct {
|
||||
Properties SuisseMobileProperties `json:"properties"`
|
||||
Geometry SuisseMobileGeometry `json:"geometry"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
sess := requests.New(requests.URL("https://schweizmobil.ch"))
|
||||
resp, _ := sess.DoRequest(context.Background(),
|
||||
requests.Path("/api/6/tracks/1856337628"),
|
||||
)
|
||||
|
||||
var response SuisseMobileResponse
|
||||
err := json.Unmarshal(resp.Content.Bytes(), &response)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var gpxFile gpx.GPX
|
||||
var gpxTrack gpx.GPXTrack
|
||||
|
||||
gpxFile.Name = response.Properties.Name
|
||||
|
||||
for _, segments := range response.Geometry.Segments {
|
||||
var gpxTrackSegment gpx.GPXTrackSegment
|
||||
|
||||
for _, point := range segments {
|
||||
fmt.Println(point)
|
||||
var gpxPoint gpx.GPXPoint
|
||||
|
||||
gpxPoint.Longitude = point[0]
|
||||
gpxPoint.Latitude = point[1]
|
||||
gpxPoint.Elevation = *gpx.NewNullableFloat64(point[2])
|
||||
|
||||
gpxTrackSegment.AppendPoint(&gpxPoint)
|
||||
}
|
||||
|
||||
gpxTrack.AppendSegment(&gpxTrackSegment)
|
||||
}
|
||||
|
||||
gpxFile.AppendTrack(&gpxTrack)
|
||||
xml, err := gpxFile.ToXml(gpx.ToXmlParams{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
file, err := os.Create("1856337628.gpx")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = file.Write(xml)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue