From ab55f0981e3568b027d44fb4e9ae2fc85c03ea9c Mon Sep 17 00:00:00 2001 From: kurihada Date: Thu, 26 Feb 2026 21:00:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=B0=E7=82=B9=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=99=84=E8=BF=91=E4=BC=98=E5=85=88=20=E2=80=94=20=E9=80=8F?= =?UTF-8?q?=E4=BC=A0=E7=94=A8=E6=88=B7=E5=9D=90=E6=A0=87=E7=BB=99=E9=AB=98?= =?UTF-8?q?=E5=BE=B7=20inputtips?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/location/suggest/route.ts | 5 +++++ src/app/panic/page.tsx | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/api/location/suggest/route.ts b/src/app/api/location/suggest/route.ts index b6abef4..35242f3 100644 --- a/src/app/api/location/suggest/route.ts +++ b/src/app/api/location/suggest/route.ts @@ -8,10 +8,15 @@ export const GET = apiHandler(async (req) => { const apiKey = requireAmapApiKey(); + const location = req.nextUrl.searchParams.get("location"); + const url = new URL("https://restapi.amap.com/v3/assistant/inputtips"); url.searchParams.set("key", apiKey); url.searchParams.set("keywords", keywords); url.searchParams.set("datatype", "poi"); + if (location) { + url.searchParams.set("location", location); + } let data; try { diff --git a/src/app/panic/page.tsx b/src/app/panic/page.tsx index cda186a..e7241c0 100644 --- a/src/app/panic/page.tsx +++ b/src/app/panic/page.tsx @@ -69,7 +69,11 @@ export default function PanicPage() { } setFetchingSuggestions(true); try { - const res = await fetch(`/api/location/suggest?keywords=${encodeURIComponent(query)}`); + const params = new URLSearchParams({ keywords: query }); + if (geo.coords) { + params.set("location", `${geo.coords.lng},${geo.coords.lat}`); + } + const res = await fetch(`/api/location/suggest?${params.toString()}`); if (!res.ok) { setSuggestions([]); setShowSuggestions(false); return; } const data: LocationSuggestion[] = await res.json(); setSuggestions(Array.isArray(data) ? data : []); @@ -79,7 +83,7 @@ export default function PanicPage() { } finally { setFetchingSuggestions(false); } - }, []); + }, [geo.coords]); const handleLocationInput = (val: string) => { setLocationQuery(val);