Update: 2026-06-29 23:09:43
This commit is contained in:
48
loction_server/siro/ride/location/update_location.php
Executable file
48
loction_server/siro/ride/location/update_location.php
Executable file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
include "../../connect.php";
|
||||
|
||||
// استقبال البيانات من تطبيق السائق
|
||||
$driver_id = filterRequest("driver_id");
|
||||
$lat = filterRequest("lat");
|
||||
$lng = filterRequest("lng");
|
||||
$heading = filterRequest("heading"); // اتجاه السيارة
|
||||
$speed = filterRequest("speed");
|
||||
$status = filterRequest("status"); // 'on' (متاح) أو 'off' (مشغول/غير متاح)
|
||||
|
||||
if (!$driver_id || !$lat || !$lng) {
|
||||
printFailure("Missing Data");
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// استخدام ON DUPLICATE KEY UPDATE لضمان وجود صف واحد فقط لكل سائق
|
||||
// الجدول: car_locations
|
||||
$sql = "INSERT INTO car_locations (driver_id, latitude, longitude, heading, speed, status, updated_at)
|
||||
VALUES (:id, :lat, :lng, :head, :spd, :stat, NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
latitude = :lat,
|
||||
longitude = :lng,
|
||||
heading = :head,
|
||||
speed = :spd,
|
||||
status = :stat,
|
||||
updated_at = NOW()";
|
||||
|
||||
$stmt = $con_tracking->prepare($sql);
|
||||
$stmt->execute([
|
||||
':id' => $driver_id,
|
||||
':lat' => $lat,
|
||||
':lng' => $lng,
|
||||
':head' => $heading,
|
||||
':spd' => $speed,
|
||||
':stat' => $status
|
||||
]);
|
||||
|
||||
// ملاحظة: لا نحتاج لإرسال socket notification هنا لأن هذا يحدث كل ثانية
|
||||
// الراكب يرى التحديث لأنه متصل بسوكيت اللوكيشن ويستمع لحدث 'update_driver_location'
|
||||
|
||||
printSuccess("Location Updated");
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printFailure("DB Error: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user