Skip to content

Commit

Permalink
🐛 skip stopovers without geometry (#3148)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu authored Jan 14, 2025
1 parent 4b07ee7 commit 0c17764
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/Http/Controllers/Backend/Support/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0c17764

Please sign in to comment.