Skip to content

Commit 55c0e8f

Browse files
committed
🐛 catch error while parsing GeoJSON
1 parent 3df8ef9 commit 55c0e8f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,18 @@ public function calculateLivePosition(): ?LivePointDto {
126126
}
127127

128128
private function getDistanceFromGeoJson(stdClass $geoJson): int {
129-
$fullD = 0;
129+
$fullDistance = 0;
130130
$lastStopover = null;
131131
foreach ($geoJson->features as $stopover) {
132132
$stopover = Coordinate::fromGeoJson($stopover);
133-
if ($lastStopover === null) {
133+
if ($lastStopover === null || $stopover === null) {
134134
$lastStopover = $stopover;
135135
continue;
136136
}
137-
$fullD += (new LineSegment($lastStopover, $stopover))->calculateDistance();
137+
$fullDistance += (new LineSegment($lastStopover, $stopover))->calculateDistance();
138138
$lastStopover = $stopover;
139139
}
140-
141-
return $fullD;
140+
return $fullDistance;
142141
}
143142

144143
/**

0 commit comments

Comments
 (0)