mirror of
https://github.com/zvx-echo6/navi.git
synced 2026-05-20 22:54:42 +02:00
feat(search): add viewport bias for location-aware geocoding
- Add mapCenter state to store (lat/lon/zoom) - Track map center on moveend in MapView - Pass mapCenter to searchGeocode from SearchBar - Update searchGeocode API call to include viewport params Search results now prioritize locations near the current map view. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
ec6f4254b9
commit
b12ebe672e
4 changed files with 158 additions and 3 deletions
|
|
@ -10,8 +10,11 @@ const VALHALLA_HEIGHT_URL = '/valhalla/height'
|
|||
* @param {AbortSignal} signal
|
||||
* @returns {Promise<{query, results, count}>}
|
||||
*/
|
||||
export async function searchGeocode(query, limit = 6, signal) {
|
||||
export async function searchGeocode(query, limit = 6, signal, viewport = null) {
|
||||
const params = new URLSearchParams({ q: query, limit: String(limit) })
|
||||
if (viewport?.lat != null) params.set('lat', String(viewport.lat))
|
||||
if (viewport?.lon != null) params.set('lon', String(viewport.lon))
|
||||
if (viewport?.zoom != null) params.set('zoom', String(Math.round(viewport.zoom)))
|
||||
const resp = await fetch(`${GEOCODE_URL}?${params}`, { signal, timeout: 5000 })
|
||||
if (!resp.ok) throw new Error(`Geocode error: ${resp.status}`)
|
||||
return resp.json()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue