mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
Switch location bias from a point to a bounding box for improved autocomplete accuracy and validation.
This commit is contained in:
@@ -39,8 +39,13 @@ router.post('/autocomplete', authenticate, async (req: Request, res: Response) =
|
||||
return res.status(400).json({ error: 'Input is required' });
|
||||
}
|
||||
|
||||
if (locationBias && (!Number.isFinite(locationBias.lat) || !Number.isFinite(locationBias.lng))) {
|
||||
return res.status(400).json({ error: 'Invalid locationBias: lat and lng must be finite numbers' });
|
||||
if (locationBias) {
|
||||
const { low, high } = locationBias;
|
||||
if (!low || !high
|
||||
|| !Number.isFinite(low.lat) || !Number.isFinite(low.lng)
|
||||
|| !Number.isFinite(high.lat) || !Number.isFinite(high.lng)) {
|
||||
return res.status(400).json({ error: 'Invalid locationBias: low and high must have finite lat and lng' });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -48,7 +53,7 @@ router.post('/autocomplete', authenticate, async (req: Request, res: Response) =
|
||||
authReq.user.id,
|
||||
input,
|
||||
lang as string,
|
||||
locationBias as { lat: number; lng: number } | undefined,
|
||||
locationBias as { low: { lat: number; lng: number }; high: { lat: number; lng: number } } | undefined,
|
||||
);
|
||||
res.json(result);
|
||||
} catch (err: unknown) {
|
||||
|
||||
@@ -319,7 +319,7 @@ export async function autocompletePlaces(
|
||||
userId: number,
|
||||
input: string,
|
||||
lang?: string,
|
||||
locationBias?: { lat: number; lng: number },
|
||||
locationBias?: { low: { lat: number; lng: number }; high: { lat: number; lng: number } },
|
||||
): Promise<{ suggestions: { placeId: string; mainText: string; secondaryText: string }[]; source: string }> {
|
||||
const apiKey = getMapsKey(userId);
|
||||
|
||||
@@ -333,9 +333,9 @@ export async function autocompletePlaces(
|
||||
};
|
||||
if (locationBias) {
|
||||
body.locationBias = {
|
||||
circle: {
|
||||
center: { latitude: locationBias.lat, longitude: locationBias.lng },
|
||||
radius: 50000.0,
|
||||
rectangle: {
|
||||
low: { latitude: locationBias.low.lat, longitude: locationBias.low.lng },
|
||||
high: { latitude: locationBias.high.lat, longitude: locationBias.high.lng },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user