Skip to content

Commit 0c17764

Browse files
authored
🐛 skip stopovers without geometry (#3148)
1 parent 4b07ee7 commit 0c17764

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

app/Http/Controllers/Backend/Support/LocationController.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,19 @@ public function calculateDistance(): int {
287287
$geoJson = $this->getPolylineBetween();
288288
$lastStopover = null;
289289
foreach ($geoJson->features as $stopover) {
290-
if ($lastStopover !== null) {
291-
$distance += (new LineSegment(
292-
new Coordinate(
293-
$lastStopover->geometry->coordinates[1],
294-
$lastStopover->geometry->coordinates[0]
295-
),
296-
new Coordinate($stopover->geometry->coordinates[1], $stopover->geometry->coordinates[0])
297-
))->calculateDistance();
290+
if ($lastStopover === null || !isset($stopover->geometry->coordinates[0]) || !isset($stopover->geometry->coordinates[1])) {
291+
$lastStopover = $stopover;
292+
continue;
298293
}
299294

295+
$distance += (new LineSegment(
296+
new Coordinate(
297+
$lastStopover->geometry->coordinates[1],
298+
$lastStopover->geometry->coordinates[0]
299+
),
300+
new Coordinate($stopover->geometry->coordinates[1], $stopover->geometry->coordinates[0])
301+
))->calculateDistance();
302+
300303
$lastStopover = $stopover;
301304
}
302305
} catch (JsonException $e) {

0 commit comments

Comments
 (0)