updates on the changes on warning and lat and long fixed to make it good
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
* and falls back seamlessly to Haversine with a 1.3 road winding multiplier.
|
||||
*/
|
||||
|
||||
import { coordsOf } from '@/lib/coords';
|
||||
|
||||
let lastRouteDurationMin = null;
|
||||
|
||||
export const getLastRouteDurationMin = () => lastRouteDurationMin;
|
||||
@@ -15,15 +17,27 @@ export const getLastRouteDurationMin = () => lastRouteDurationMin;
|
||||
* @returns {Promise<{ distance: number, minutes: number, polyline: Array<[number, number]>, resolved: boolean }>}
|
||||
*/
|
||||
export const calculateDrivingRoute = async (origin, destination) => {
|
||||
const lat1 = Number(origin?.latitude);
|
||||
const lon1 = Number(origin?.longitude);
|
||||
const lat2 = Number(destination?.latitude);
|
||||
const lon2 = Number(destination?.longitude);
|
||||
|
||||
if (!Number.isFinite(lat1) || !Number.isFinite(lon1) || !Number.isFinite(lat2) || !Number.isFinite(lon2)) {
|
||||
// Validated through lib/coords rather than with Number.isFinite.
|
||||
//
|
||||
// The previous guard was `Number.isFinite(Number(value))`, which accepts
|
||||
// null, '' and false — all three coerce to 0, and 0 is finite. A missing pin
|
||||
// therefore reached OSRM as (0, 0). OSRM answers HTTP 200 with no `routes`
|
||||
// for a point in open ocean, so control fell through to the Haversine
|
||||
// fallback below and a Coimbatore pickup measured against 0,0 returned
|
||||
// roughly 11,000 km. That number becomes the row's charge and the backend
|
||||
// honours it verbatim, so the guard being wrong here was a billing defect,
|
||||
// not a display one.
|
||||
const from = coordsOf(origin);
|
||||
const to = coordsOf(destination);
|
||||
if (!from || !to) {
|
||||
throw new Error("Invalid coordinates");
|
||||
}
|
||||
|
||||
const lat1 = from.latitude;
|
||||
const lon1 = from.longitude;
|
||||
const lat2 = to.latitude;
|
||||
const lon2 = to.longitude;
|
||||
|
||||
// 1. Try OSRM API with full GeoJSON geometry for live polyline map preview
|
||||
const osrmBaseUrl =
|
||||
(typeof import.meta !== 'undefined' && import.meta?.env?.VITE_OSRM_URL) ||
|
||||
|
||||
Reference in New Issue
Block a user