Add data to routes

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

View File

@ -2,6 +2,7 @@ package routing
import (
"fmt"
"time"
"github.com/paulmach/orb"
)
@ -20,8 +21,15 @@ func NewRoutingService(service_type string, baseUrl string) (RoutingService, err
type Route struct {
Summary RouteSummary
Legs []RouteLeg
}
type RouteSummary struct {
Polyline string
}
type RouteLeg struct {
Distance float64
Duration time.Duration
Polyline string
}

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
}