Add data to routes

This commit is contained in:
2023-03-29 12:51:09 +02:00
parent fb30573934
commit a2dc346ed5
2 changed files with 20 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"io/ioutil"
"net/http"
"time"
"git.coopgo.io/coopgo-platform/routing-service/encoding/polylines"
"git.coopgo.io/coopgo-platform/routing-service/proto/valhalla"
@@ -55,16 +56,27 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
decodedLinestring := orb.LineString{}
legs := []RouteLeg{}
for _, leg := range resp.Directions.Routes[0].Legs {
shape := leg.Shape
decodedShape := polylines.Decode(&shape, 6)
decodedLinestring = append(decodedLinestring, decodedShape...)
routeLeg := RouteLeg{
Distance: float64(leg.Summary.Length),
Duration: time.Duration(leg.Summary.Time) * time.Second,
Polyline: polylines.Encode(decodedShape),
}
legs = append(legs, routeLeg)
}
return &Route{
Summary: RouteSummary{
Polyline: polylines.Encode(decodedLinestring),
},
Legs: legs,
}, nil
}