mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-21 05:58:23 +02:00
Update location lookup to use OpenStreetMap for better accuracy
Switch from Visual Crossing to Nominatim (OpenStreetMap) for reverse geocoding to improve city and country identification from GPS coordinates. Replit-Commit-Author: Agent Replit-Commit-Session-Id: d43bd811-9372-45a7-8ac9-4a954c0538e1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/d43bd811-9372-45a7-8ac9-4a954c0538e1/zoZabWF
This commit is contained in:
1 parent
5045c98692
commit
5133f52d2a
1 file changed
+23
-16
+23
-16
@@ -244,43 +244,50 @@ export class WeatherService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convertit les coordonnées GPS en nom de ville via l'API Visual Crossing
|
* Convertit les coordonnées GPS en nom de ville via l'API de géocodage inverse Nominatim (OpenStreetMap)
|
||||||
*/
|
*/
|
||||||
async getCityFromCoordinates(latitude: number, longitude: number, apiKey: string): Promise<{ city: string; country: string; fullLocation: string } | null> {
|
async getCityFromCoordinates(latitude: number, longitude: number, apiKey: string): Promise<{ city: string; country: string; fullLocation: string } | null> {
|
||||||
try {
|
try {
|
||||||
const url = `${this.baseUrl}/${latitude},${longitude}?unitGroup=metric&include=current&key=${apiKey}&contentType=json`;
|
// Utiliser l'API Nominatim (OpenStreetMap) pour la géolocalisation inverse
|
||||||
|
const nominatimUrl = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}&accept-language=fr`;
|
||||||
|
|
||||||
console.log('🌍 Géolocalisation:', { latitude, longitude });
|
console.log('🌍 Géolocalisation via Nominatim:', { latitude, longitude });
|
||||||
|
|
||||||
|
const response = await fetch(nominatimUrl, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'LogiFlow-Weather-System/1.0 (Enterprise Weather Management Platform)'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const response = await fetch(url);
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error(`Geolocation API error: ${response.status} ${response.statusText}`);
|
console.error(`Nominatim API error: ${response.status} ${response.statusText}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
console.log('🌍 API Response:', JSON.stringify(data, null, 2));
|
console.log('🌍 Nominatim Response:', JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
// L'API Visual Crossing retourne les informations de localisation
|
if (data && data.address) {
|
||||||
if (data.resolvedAddress) {
|
const address = data.address;
|
||||||
const address = data.resolvedAddress;
|
|
||||||
const parts = address.split(',').map((part: string) => part.trim());
|
|
||||||
|
|
||||||
// Extraire la ville et le pays de l'adresse
|
// Extraire la ville (peut être dans city, town, village, municipality, etc.)
|
||||||
const city = parts[0] || 'Ville inconnue';
|
const city = address.city || address.town || address.village || address.municipality || address.hamlet || 'Ville inconnue';
|
||||||
const country = parts[parts.length - 1] || 'Pays inconnu';
|
const country = address.country || 'Pays inconnu';
|
||||||
|
|
||||||
console.log('🌍 Parsed location:', { city, country, fullLocation: address });
|
// Créer une adresse lisible pour Visual Crossing
|
||||||
|
const fullLocation = `${city}, ${country}`;
|
||||||
|
|
||||||
|
console.log('🌍 Parsed location:', { city, country, fullLocation });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
city,
|
city,
|
||||||
country,
|
country,
|
||||||
fullLocation: address
|
fullLocation
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('🌍 No resolvedAddress found in API response');
|
console.log('🌍 No address found in Nominatim response');
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur lors de la géolocalisation:", error);
|
console.error("Erreur lors de la géolocalisation:", error);
|
||||||
|
|||||||
Reference in new issue
Block a user