updates on the ui changes and the ai bot implementation

This commit is contained in:
2026-08-19 11:19:51 +05:30
parent 5284fc75bc
commit bdb21766f2
27 changed files with 2607 additions and 278 deletions

View File

@@ -6,6 +6,13 @@
* @param {Object} destination - { latitude, longitude }
* @returns {Promise<number>} - Round distance in KM
*/
// Duration from the most recent OSRM route, in minutes, or null when the
// Haversine fallback was used (a straight-line estimate has no honest
// duration — better to show nothing than a made-up ETA).
let lastRouteDurationMin = null;
export const getLastRouteDurationMin = () => lastRouteDurationMin;
export const calculateDrivingDistance = async (origin, destination) => {
const lat1 = origin?.latitude;
const lon1 = origin?.longitude;
@@ -26,6 +33,10 @@ export const calculateDrivingDistance = async (origin, destination) => {
if (data.routes && data.routes.length > 0) {
const distanceInMeters = data.routes[0].distance;
const distanceInKm = distanceInMeters / 1000;
// OSRM already returns the driving duration alongside the distance;
// it was being discarded. Cached here so callers that want an ETA get
// a REAL routed figure instead of dividing km by a guessed speed.
lastRouteDurationMin = Number.isFinite(data.routes[0].duration) ? Math.round(data.routes[0].duration / 60) : null;
return Math.round(distanceInKm);
}
}
@@ -44,7 +55,9 @@ export const calculateDrivingDistance = async (origin, destination) => {
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const aerialDistance = R * c;
// No route was fetched, so there is no honest duration to report.
lastRouteDurationMin = null;
return Math.round(aerialDistance * 1.3);
};