fix decoding encoreding
This commit is contained in:
10
valhalla.go
10
valhalla.go
@@ -10,6 +10,7 @@ import (
|
||||
"git.coopgo.io/coopgo-platform/routing-service/encoding/polylines"
|
||||
"git.coopgo.io/coopgo-platform/routing-service/proto/valhalla"
|
||||
"github.com/paulmach/orb"
|
||||
"github.com/rs/zerolog/log"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -47,11 +48,14 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
||||
|
||||
resp, err := v.protocolBufferRequest(request, "route")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("pb request to valhalla error")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug().Any("resp", resp).Msg("valhalla response")
|
||||
|
||||
if resp.Directions == nil || resp.Directions.Routes == nil || len(resp.Directions.Routes) < 1 {
|
||||
return nil, errors.New("no routes returnes by valhalla")
|
||||
return nil, errors.New("no routes returned by valhalla")
|
||||
}
|
||||
|
||||
decodedLinestring := orb.LineString{}
|
||||
@@ -66,7 +70,7 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
||||
routeLeg := RouteLeg{
|
||||
Distance: float64(leg.Summary.Length),
|
||||
Duration: time.Duration(leg.Summary.Time) * time.Second,
|
||||
Polyline: polylines.Encode(decodedShape),
|
||||
Polyline: polylines.Encode(decodedShape, 5),
|
||||
}
|
||||
|
||||
legs = append(legs, routeLeg)
|
||||
@@ -74,7 +78,7 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
||||
|
||||
return &Route{
|
||||
Summary: RouteSummary{
|
||||
Polyline: polylines.Encode(decodedLinestring),
|
||||
Polyline: polylines.Encode(decodedLinestring, 5),
|
||||
},
|
||||
Legs: legs,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user