Update: 2026-07-13 22:23:21

This commit is contained in:
Hamza-Ayed
2026-07-13 22:23:22 +03:00
parent fd3f4a365a
commit c6f48a1f91
45 changed files with 3533 additions and 36 deletions
+40
View File
@@ -0,0 +1,40 @@
// utils/polyline.js — ترميز Google Polyline القياسي (يطابق PolylineUtils.decode في تطبيقات الفلاتر)
export function encodePolyline(points) {
let output = ''
let prevLat = 0
let prevLng = 0
for (const [lat, lng] of points) {
const lat5 = Math.round(lat * 1e5)
const lng5 = Math.round(lng * 1e5)
output += encodeValue(lat5 - prevLat)
output += encodeValue(lng5 - prevLng)
prevLat = lat5
prevLng = lng5
}
return output
}
function encodeValue(value) {
let v = value < 0 ? ~(value << 1) : value << 1
let output = ''
while (v >= 0x20) {
output += String.fromCharCode((0x20 | (v & 0x1f)) + 63)
v >>= 5
}
output += String.fromCharCode(v + 63)
return output
}
// هافرسين — مسافة بالمتر بين نقطتين
export function haversineMeters(lat1, lng1, lat2, lng2) {
const R = 6371000
const dLat = deg2rad(lat2 - lat1)
const dLng = deg2rad(lng2 - lng1)
const a =
Math.sin(dLat / 2) ** 2 +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLng / 2) ** 2
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
}
function deg2rad(d) { return (d * Math.PI) / 180 }