valhalla implementation changes
This commit is contained in:
parent
d03cd41008
commit
faabcc54f5
12
routing.go
12
routing.go
|
@ -20,16 +20,16 @@ func NewRoutingService(service_type string, baseUrl string) (RoutingService, err
|
|||
}
|
||||
|
||||
type Route struct {
|
||||
Summary RouteSummary
|
||||
Summary
|
||||
Legs []RouteLeg
|
||||
}
|
||||
|
||||
type RouteSummary struct {
|
||||
Polyline string
|
||||
}
|
||||
|
||||
type RouteLeg struct {
|
||||
type Summary struct {
|
||||
Distance float64
|
||||
Duration time.Duration
|
||||
Polyline string
|
||||
}
|
||||
|
||||
type RouteLeg struct {
|
||||
Summary
|
||||
}
|
||||
|
|
19
valhalla.go
19
valhalla.go
|
@ -25,7 +25,6 @@ func NewValhallaRouting(baseURL string) (*ValhallaRouting, error) {
|
|||
}
|
||||
|
||||
func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error) {
|
||||
|
||||
valhalla_locations := []*valhalla.Location{}
|
||||
|
||||
for _, loc := range locations {
|
||||
|
@ -57,6 +56,8 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
|||
}
|
||||
|
||||
decodedLinestring := orb.LineString{}
|
||||
routeDuration := time.Duration(0)
|
||||
routeLength := 0.0
|
||||
|
||||
legs := []RouteLeg{}
|
||||
|
||||
|
@ -65,17 +66,27 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
|||
decodedShape := polylines.Decode(&shape, 6)
|
||||
decodedLinestring = append(decodedLinestring, decodedShape...)
|
||||
|
||||
length := float64(leg.Summary.Length)
|
||||
routeLength = routeLength + length
|
||||
|
||||
duration := time.Duration(leg.Summary.Time) * time.Second
|
||||
routeDuration = routeDuration + duration
|
||||
|
||||
routeLeg := RouteLeg{
|
||||
Distance: float64(leg.Summary.Length),
|
||||
Duration: time.Duration(leg.Summary.Time) * time.Second,
|
||||
Summary: Summary{
|
||||
Distance: float64(length),
|
||||
Duration: duration,
|
||||
Polyline: polylines.Encode(decodedShape, 5),
|
||||
},
|
||||
}
|
||||
|
||||
legs = append(legs, routeLeg)
|
||||
}
|
||||
|
||||
return &Route{
|
||||
Summary: RouteSummary{
|
||||
Summary: Summary{
|
||||
Distance: routeLength,
|
||||
Duration: routeDuration,
|
||||
Polyline: polylines.Encode(decodedLinestring, 5),
|
||||
},
|
||||
Legs: legs,
|
||||
|
|
Loading…
Reference in New Issue