From 85ddea41e4b72bea2c21d2530ea9e6b1766a92b3 Mon Sep 17 00:00:00 2001 From: Eric F Date: Sun, 14 Jun 2026 08:32:24 -0400 Subject: [PATCH] fix: restore getPlaceDetails with Nominatim OSM implementation - Replace stub with working Nominatim OSM place details lookup - Fixes 'Failed to find Server Action' errors in logs - Free, no API key required --- .../lib/server/actions/map/getPlaceDetails.ts | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/tools/citrineos-core-main/apps/operator-ui/src/lib/server/actions/map/getPlaceDetails.ts b/tools/citrineos-core-main/apps/operator-ui/src/lib/server/actions/map/getPlaceDetails.ts index 3d40ce0..bf40fb6 100644 --- a/tools/citrineos-core-main/apps/operator-ui/src/lib/server/actions/map/getPlaceDetails.ts +++ b/tools/citrineos-core-main/apps/operator-ui/src/lib/server/actions/map/getPlaceDetails.ts @@ -38,13 +38,49 @@ export async function getPlaceDetails( throw new Error('Place ID is required'); } - // Return stub data - Google Places API removed, using OSM/Nominatim instead - return { - id: placeId, - displayName: { text: '', languageCode: 'en' }, - formattedAddress: '', - addressComponents: [], - location: { latitude: 0, longitude: 0 }, - }; + try { + // Use Nominatim OSM for place details (free, no API key) + const url = `https://nominatim.openstreetmap.org/lookup?format=json&osm_ids=${placeId}&addressdetails=1`; + const response = await fetch(url, { + headers: { 'User-Agent': 'CitrineOS-Operator-UI/1.0' }, + }); + + if (!response.ok) { + throw new Error(`Nominatim error: ${response.status}`); + } + + const data = await response.json(); + if (data && data.length > 0) { + const place = data[0]; + return { + id: place.place_id?.toString() || placeId, + displayName: { text: place.display_name || '', languageCode: 'en' }, + formattedAddress: place.display_name || '', + addressComponents: [], + location: { + latitude: parseFloat(place.lat) || 0, + longitude: parseFloat(place.lon) || 0, + }, + types: place.type ? [place.type] : [], + }; + } + + return { + id: placeId, + displayName: { text: '', languageCode: 'en' }, + formattedAddress: '', + addressComponents: [], + location: { latitude: 0, longitude: 0 }, + }; + } catch (error) { + console.error('getPlaceDetails error:', error); + return { + id: placeId, + displayName: { text: '', languageCode: 'en' }, + formattedAddress: '', + addressComponents: [], + location: { latitude: 0, longitude: 0 }, + }; + } }); }