feat: 地点搜索附近优先 — 透传用户坐标给高德 inputtips
This commit is contained in:
@@ -8,10 +8,15 @@ export const GET = apiHandler(async (req) => {
|
|||||||
|
|
||||||
const apiKey = requireAmapApiKey();
|
const apiKey = requireAmapApiKey();
|
||||||
|
|
||||||
|
const location = req.nextUrl.searchParams.get("location");
|
||||||
|
|
||||||
const url = new URL("https://restapi.amap.com/v3/assistant/inputtips");
|
const url = new URL("https://restapi.amap.com/v3/assistant/inputtips");
|
||||||
url.searchParams.set("key", apiKey);
|
url.searchParams.set("key", apiKey);
|
||||||
url.searchParams.set("keywords", keywords);
|
url.searchParams.set("keywords", keywords);
|
||||||
url.searchParams.set("datatype", "poi");
|
url.searchParams.set("datatype", "poi");
|
||||||
|
if (location) {
|
||||||
|
url.searchParams.set("location", location);
|
||||||
|
}
|
||||||
|
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -69,7 +69,11 @@ export default function PanicPage() {
|
|||||||
}
|
}
|
||||||
setFetchingSuggestions(true);
|
setFetchingSuggestions(true);
|
||||||
try {
|
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; }
|
if (!res.ok) { setSuggestions([]); setShowSuggestions(false); return; }
|
||||||
const data: LocationSuggestion[] = await res.json();
|
const data: LocationSuggestion[] = await res.json();
|
||||||
setSuggestions(Array.isArray(data) ? data : []);
|
setSuggestions(Array.isArray(data) ? data : []);
|
||||||
@@ -79,7 +83,7 @@ export default function PanicPage() {
|
|||||||
} finally {
|
} finally {
|
||||||
setFetchingSuggestions(false);
|
setFetchingSuggestions(false);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [geo.coords]);
|
||||||
|
|
||||||
const handleLocationInput = (val: string) => {
|
const handleLocationInput = (val: string) => {
|
||||||
setLocationQuery(val);
|
setLocationQuery(val);
|
||||||
|
|||||||
Reference in New Issue
Block a user