fix: correct destination initialization and response handling

This commit makes corrections to the initialization of the dests array to 
ensure it properly allocates space for each destination. It also fixes the 
response handling by correctly extending the response structure after 
the loop, improving overall stability and accuracy of the distance 
matrix request handling.
This commit is contained in:
2025-02-16 16:23:41 +01:00
parent 53c89cb7e4
commit b3e9b723a4
2 changed files with 12 additions and 25 deletions
+5 -3
View File
@@ -151,7 +151,9 @@ func handleDistanceMatrixRequest(w http.ResponseWriter, r *http.Request, client
res := distanceResponse{}
dests := make([][]destination, len(origins))
for i := range dests {
dests[i] = make([]destination, len(destinations))
}
for {
elem, err := response.Recv()
if err != nil {
@@ -164,7 +166,7 @@ func handleDistanceMatrixRequest(w http.ResponseWriter, r *http.Request, client
}
ll := destinations[*elem.DestinationIndex].Waypoint.GetLocation().LatLng
dests[*elem.OriginIndex] = append(dests[*elem.OriginIndex], destination{
dests[*elem.OriginIndex][*elem.DestinationIndex] = destination{
Destination: fmt.Sprintf("%f,%f", ll.Latitude, ll.Longitude),
Distance: distance{
Text: string(elem.DistanceMeters),
@@ -174,7 +176,7 @@ func handleDistanceMatrixRequest(w http.ResponseWriter, r *http.Request, client
elem.Duration.AsDuration().String(),
elem.Duration.AsDuration().Minutes(),
},
})
}
}
for i, dest := range dests {
res.Origins = append(res.Origins, origin{origins[i].Waypoint.GetAddress(), dest})