fix: explicitly cast geometry to SRID 4326 in ST_Distance_Sphere to prevent SRID mismatch errors permanently

This commit is contained in:
Tazyeuu
2026-06-11 02:10:33 +07:00
parent 14120dc683
commit e7d437f201
4 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ $lat = (float)($_GET['lat'] ?? 0); $lng = (float)($_GET['lng'] ?? 0);
if (!$lat || !$lng) sendError('lat dan lng wajib diisi');
$wkt = sprintf('POINT(%F %F)', $lng, $lat);
$stmt = $pdo->prepare("SELECT id, nama, buka_24_jam, ST_AsGeoJSON(geom) as geojson,
ST_Distance_Sphere(geom, ST_GeomFromText(?)) / 1000 as jarak_km
ST_Distance_Sphere(ST_SRID(geom, 4326), ST_SRID(ST_GeomFromText(?), 4326)) / 1000 as jarak_km
FROM spbu ORDER BY jarak_km ASC LIMIT 1");
$stmt->execute([$wkt]);
$r = $stmt->fetch();