Return full findmydevice history paths
This commit is contained in:
+5
-45
@@ -14,6 +14,10 @@ header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Expires: 0');
|
||||
|
||||
if (function_exists('set_time_limit')) {
|
||||
@set_time_limit(0);
|
||||
}
|
||||
|
||||
custom_require_auth();
|
||||
|
||||
$requestData = custom_read_request_data();
|
||||
@@ -77,7 +81,6 @@ if ($startParam && $endParam) {
|
||||
// API URL 생성
|
||||
$historyEndpoint = "/history/period/{$startTime}?filter_entity_id=" . rawurlencode($entities['device']) . "&end_time={$endTime}";
|
||||
$includeHistory = isset($_GET['history']) && $_GET['history'] === '1' && !isset($_GET['hashonly']);
|
||||
$historyMaxPoints = max(20, min(1200, (int)($_GET['maxPoints'] ?? 800)));
|
||||
|
||||
// 공통 요청 함수
|
||||
function getData($entityId) {
|
||||
@@ -202,7 +205,7 @@ $ascendedData = getData($fascendedUrl);
|
||||
$descendedData = getData($fdescendedUrl);
|
||||
$stepsData = getData($stepsUrl);
|
||||
$distanceData = getData($distanceUrl);
|
||||
$historyData = $includeHistory ? (custom_ha_request('seoul', 'GET', $historyEndpoint) ?? []) : [];
|
||||
$historyData = $includeHistory ? (custom_ha_request('seoul', 'GET', $historyEndpoint, null, 0) ?? []) : [];
|
||||
$triggerData = getData($triggerUrl);
|
||||
|
||||
// 경로 기록
|
||||
@@ -218,49 +221,6 @@ if (isset($historyData[0])) {
|
||||
}
|
||||
}
|
||||
|
||||
function path_distance_m(array $a, array $b): float
|
||||
{
|
||||
$earth = 6371000;
|
||||
$lat1 = deg2rad((float)$a['lat']);
|
||||
$lat2 = deg2rad((float)$b['lat']);
|
||||
$dLat = $lat2 - $lat1;
|
||||
$dLng = deg2rad((float)$b['lng'] - (float)$a['lng']);
|
||||
$h = sin($dLat / 2) ** 2 + cos($lat1) * cos($lat2) * sin($dLng / 2) ** 2;
|
||||
return 2 * $earth * asin(min(1, sqrt($h)));
|
||||
}
|
||||
|
||||
function simplify_path(array $path, int $maxPoints): array
|
||||
{
|
||||
$count = count($path);
|
||||
if ($count <= $maxPoints) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$filtered = [];
|
||||
$last = null;
|
||||
foreach ($path as $point) {
|
||||
if ($last === null || path_distance_m($last, $point) >= 5) {
|
||||
$filtered[] = $point;
|
||||
$last = $point;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($filtered) <= $maxPoints) {
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
$sampled = [];
|
||||
$lastIndex = count($filtered) - 1;
|
||||
for ($i = 0; $i < $maxPoints; $i++) {
|
||||
$idx = (int)round($i * $lastIndex / max(1, $maxPoints - 1));
|
||||
$sampled[] = $filtered[$idx];
|
||||
}
|
||||
|
||||
return $sampled;
|
||||
}
|
||||
|
||||
$path = simplify_path($path, $historyMaxPoints);
|
||||
|
||||
$lang = $_GET['lang'] ?? 'en';
|
||||
|
||||
$activityMap = [
|
||||
|
||||
Reference in New Issue
Block a user