Add data to routes
This commit is contained in:
parent
fb30573934
commit
a2dc346ed5
|
@ -2,6 +2,7 @@ package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/paulmach/orb"
|
"github.com/paulmach/orb"
|
||||||
)
|
)
|
||||||
|
@ -20,8 +21,15 @@ func NewRoutingService(service_type string, baseUrl string) (RoutingService, err
|
||||||
|
|
||||||
type Route struct {
|
type Route struct {
|
||||||
Summary RouteSummary
|
Summary RouteSummary
|
||||||
|
Legs []RouteLeg
|
||||||
}
|
}
|
||||||
|
|
||||||
type RouteSummary struct {
|
type RouteSummary struct {
|
||||||
Polyline string
|
Polyline string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RouteLeg struct {
|
||||||
|
Distance float64
|
||||||
|
Duration time.Duration
|
||||||
|
Polyline string
|
||||||
|
}
|
||||||
|
|
12
valhalla.go
12
valhalla.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-platform/routing-service/encoding/polylines"
|
"git.coopgo.io/coopgo-platform/routing-service/encoding/polylines"
|
||||||
"git.coopgo.io/coopgo-platform/routing-service/proto/valhalla"
|
"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{}
|
decodedLinestring := orb.LineString{}
|
||||||
|
|
||||||
|
legs := []RouteLeg{}
|
||||||
|
|
||||||
for _, leg := range resp.Directions.Routes[0].Legs {
|
for _, leg := range resp.Directions.Routes[0].Legs {
|
||||||
shape := leg.Shape
|
shape := leg.Shape
|
||||||
decodedShape := polylines.Decode(&shape, 6)
|
decodedShape := polylines.Decode(&shape, 6)
|
||||||
decodedLinestring = append(decodedLinestring, decodedShape...)
|
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{
|
return &Route{
|
||||||
Summary: RouteSummary{
|
Summary: RouteSummary{
|
||||||
Polyline: polylines.Encode(decodedLinestring),
|
Polyline: polylines.Encode(decodedLinestring),
|
||||||
},
|
},
|
||||||
|
Legs: legs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue