feat: 地点搜索附近优先 — 透传用户坐标给高德 inputtips
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user