- Creazione "AbitareGliIblei"
- Mappa Interattiva con i markers
This commit is contained in:
19
src/store/Modules/geocodingmap.ts
Normal file
19
src/store/Modules/geocodingmap.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// geocoding.ts
|
||||
export const getCityFromCoordinates = async (lat: number, lon: number): Promise<string | null> => {
|
||||
const url = `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error('Errore nella richiesta di geocoding');
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
// Controlla se la città è presente nei risultati
|
||||
return data.address?.city || data.address?.town || data.address?.village || null;
|
||||
} catch (error) {
|
||||
console.error('Errore durante il geocoding:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user