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 }, + }; + } }); }