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
This commit is contained in:
Eric F
2026-06-14 08:32:24 -04:00
parent d0c0cc8b0e
commit 85ddea41e4

View File

@@ -38,7 +38,33 @@ export async function getPlaceDetails(
throw new Error('Place ID is required');
}
// Return stub data - Google Places API removed, using OSM/Nominatim instead
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' },
@@ -46,5 +72,15 @@ export async function getPlaceDetails(
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 },
};
}
});
}