From 0c17764a235e2dea192a1265e5b7c6cf5f03f890 Mon Sep 17 00:00:00 2001 From: Kris Date: Tue, 14 Jan 2025 09:49:08 +0100 Subject: [PATCH] :bug: skip stopovers without geometry (#3148) --- .../Backend/Support/LocationController.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Backend/Support/LocationController.php b/app/Http/Controllers/Backend/Support/LocationController.php index 3e84c9492..3463760e4 100644 --- a/app/Http/Controllers/Backend/Support/LocationController.php +++ b/app/Http/Controllers/Backend/Support/LocationController.php @@ -287,16 +287,19 @@ public function calculateDistance(): int { $geoJson = $this->getPolylineBetween(); $lastStopover = null; foreach ($geoJson->features as $stopover) { - if ($lastStopover !== null) { - $distance += (new LineSegment( - new Coordinate( - $lastStopover->geometry->coordinates[1], - $lastStopover->geometry->coordinates[0] - ), - new Coordinate($stopover->geometry->coordinates[1], $stopover->geometry->coordinates[0]) - ))->calculateDistance(); + if ($lastStopover === null || !isset($stopover->geometry->coordinates[0]) || !isset($stopover->geometry->coordinates[1])) { + $lastStopover = $stopover; + continue; } + $distance += (new LineSegment( + new Coordinate( + $lastStopover->geometry->coordinates[1], + $lastStopover->geometry->coordinates[0] + ), + new Coordinate($stopover->geometry->coordinates[1], $stopover->geometry->coordinates[0]) + ))->calculateDistance(); + $lastStopover = $stopover; } } catch (JsonException $e) {