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:
Matt 2026-04-26 04:03:52 +00:00
commit b12ebe672e
4 changed files with 158 additions and 3 deletions

View file

@ -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()