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:
@@ -38,13 +38,49 @@ export async function getPlaceDetails(
|
|||||||
throw new Error('Place ID is required');
|
throw new Error('Place ID is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return stub data - Google Places API removed, using OSM/Nominatim instead
|
try {
|
||||||
return {
|
// Use Nominatim OSM for place details (free, no API key)
|
||||||
id: placeId,
|
const url = `https://nominatim.openstreetmap.org/lookup?format=json&osm_ids=${placeId}&addressdetails=1`;
|
||||||
displayName: { text: '', languageCode: 'en' },
|
const response = await fetch(url, {
|
||||||
formattedAddress: '',
|
headers: { 'User-Agent': 'CitrineOS-Operator-UI/1.0' },
|
||||||
addressComponents: [],
|
});
|
||||||
location: { latitude: 0, longitude: 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 },
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user