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 {
|
type Route struct {
|
||||||
Summary RouteSummary
|
Summary
|
||||||
Legs []RouteLeg
|
Legs []RouteLeg
|
||||||
}
|
}
|
||||||
|
|
||||||
type RouteSummary struct {
|
type Summary struct {
|
||||||
Polyline string
|
|
||||||
}
|
|
||||||
|
|
||||||
type RouteLeg struct {
|
|
||||||
Distance float64
|
Distance float64
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
Polyline string
|
Polyline string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RouteLeg struct {
|
||||||
|
Summary
|
||||||
|
}
|
||||||
|
|
23
valhalla.go
23
valhalla.go
|
@ -25,7 +25,6 @@ func NewValhallaRouting(baseURL string) (*ValhallaRouting, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error) {
|
func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error) {
|
||||||
|
|
||||||
valhalla_locations := []*valhalla.Location{}
|
valhalla_locations := []*valhalla.Location{}
|
||||||
|
|
||||||
for _, loc := range locations {
|
for _, loc := range locations {
|
||||||
|
@ -57,6 +56,8 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedLinestring := orb.LineString{}
|
decodedLinestring := orb.LineString{}
|
||||||
|
routeDuration := time.Duration(0)
|
||||||
|
routeLength := 0.0
|
||||||
|
|
||||||
legs := []RouteLeg{}
|
legs := []RouteLeg{}
|
||||||
|
|
||||||
|
@ -65,17 +66,27 @@ func (v *ValhallaRouting) Route(locations []orb.Point) (route *Route, err error)
|
||||||
decodedShape := polylines.Decode(&shape, 6)
|
decodedShape := polylines.Decode(&shape, 6)
|
||||||
decodedLinestring = append(decodedLinestring, decodedShape...)
|
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{
|
routeLeg := RouteLeg{
|
||||||
Distance: float64(leg.Summary.Length),
|
Summary: Summary{
|
||||||
Duration: time.Duration(leg.Summary.Time) * time.Second,
|
Distance: float64(length),
|
||||||
Polyline: polylines.Encode(decodedShape, 5),
|
Duration: duration,
|
||||||
|
Polyline: polylines.Encode(decodedShape, 5),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
legs = append(legs, routeLeg)
|
legs = append(legs, routeLeg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Route{
|
return &Route{
|
||||||
Summary: RouteSummary{
|
Summary: Summary{
|
||||||
|
Distance: routeLength,
|
||||||
|
Duration: routeDuration,
|
||||||
Polyline: polylines.Encode(decodedLinestring, 5),
|
Polyline: polylines.Encode(decodedLinestring, 5),
|
||||||
},
|
},
|
||||||
Legs: legs,
|
Legs: legs,
|
||||||
|
@ -96,7 +107,7 @@ func (v *ValhallaRouting) protocolBufferRequest(api *valhalla.Api, path string)
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
//resp, err := http.Post(v.BaseURL+path, "application/x-protobuf", bytes.NewBuffer(data))
|
// resp, err := http.Post(v.BaseURL+path, "application/x-protobuf", bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue