Harden findmydevice GPS jitter filtering

This commit is contained in:
seo
2026-06-18 04:24:31 +09:00
parent 08bd2ab4a4
commit 25fe661cc1
3 changed files with 117 additions and 27 deletions
+10 -1
View File
@@ -358,12 +358,19 @@ if ($historySets) {
foreach ($historyData[0] as $item) {
$lat = $item['attributes']['latitude'] ?? null;
$lng = $item['attributes']['longitude'] ?? null;
$accuracy = $item['attributes']['gps_accuracy'] ?? $item['attributes']['accuracy'] ?? null;
$time = $item['last_changed'] ?? null;
if ($lat && $lng && $time) {
$timeKey = (string)(strtotime((string)$time) ?: $time);
$key = $timeKey . ':' . round((float)$lat, 5) . ':' . round((float)$lng, 5);
if (!isset($pathByKey[$key])) {
$pathByKey[$key] = ['lat' => $lat, 'lng' => $lng, 'time' => $time, 'source' => $profile];
$pathByKey[$key] = [
'lat' => $lat,
'lng' => $lng,
'time' => $time,
'accuracy' => is_numeric($accuracy) ? (float)$accuracy : null,
'source' => $profile,
];
}
}
}
@@ -457,6 +464,8 @@ function smoothPath(array $path): array
'lat' => ((float)$prev['lat'] + ((float)$cur['lat'] * 2) + (float)$next['lat']) / 4,
'lng' => ((float)$prev['lng'] + ((float)$cur['lng'] * 2) + (float)$next['lng']) / 4,
'time' => $cur['time'],
'accuracy' => $cur['accuracy'] ?? null,
'source' => $cur['source'] ?? null,
];
}