new location with locationIQ Model and service
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'dart:convert';
|
||||
//import 'dart:convert';
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
//import 'package:http/http.dart' as http;
|
||||
import '../config/environment.dart';
|
||||
|
||||
class AppwriteService {
|
||||
@@ -168,46 +168,46 @@ class AppwriteService {
|
||||
}
|
||||
}
|
||||
|
||||
// Geocode coordinates using local proxy or Appwrite Function
|
||||
Future<String> geocodeLocation(double lat, double lon) async {
|
||||
// Wenn lokaler Proxy aktiviert ist, diesen verwenden
|
||||
if (Environment.useLocalProxy) {
|
||||
return _geocodeViaLocalProxy(lat, lon);
|
||||
}
|
||||
// // Geocode coordinates using local proxy or Appwrite Function
|
||||
// Future<String> geocodeLocation(double lat, double lon) async {
|
||||
// // Wenn lokaler Proxy aktiviert ist, diesen verwenden
|
||||
// if (Environment.useLocalProxy) {
|
||||
// return _geocodeViaLocalProxy(lat, lon);
|
||||
// }
|
||||
|
||||
// Fallback: Koordinaten zurückgeben
|
||||
return 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
}
|
||||
// // Fallback: Koordinaten zurückgeben
|
||||
// return 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
// }
|
||||
|
||||
// Geocoding über lokalen Reverse Proxy
|
||||
Future<String> _geocodeViaLocalProxy(double lat, double lon) async {
|
||||
try {
|
||||
final proxyUrl = '${Environment.localProxyUrl}/?lat=$lat&lon=$lon&apiKey=${Environment.ptvApiKey}';
|
||||
// // Geocoding über lokalen Reverse Proxy
|
||||
// Future<String> _geocodeViaLocalProxy(double lat, double lon) async {
|
||||
// try {
|
||||
// final proxyUrl = '${Environment.localProxyUrl}/?lat=$lat&lon=$lon&apiKey=${Environment.ptvApiKey}';
|
||||
|
||||
print('🔄 Verwende lokalen Proxy: ${Environment.localProxyUrl}');
|
||||
// print('🔄 Verwende lokalen Proxy: ${Environment.localProxyUrl}');
|
||||
|
||||
final response = await http.get(Uri.parse(proxyUrl));
|
||||
// final response = await http.get(Uri.parse(proxyUrl));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
// if (response.statusCode == 200) {
|
||||
// final data = jsonDecode(response.body);
|
||||
|
||||
if (data['success'] == true) {
|
||||
final location = data['location'] as String;
|
||||
print('✅ Geocoding erfolgreich (Proxy): $location');
|
||||
return location;
|
||||
} else {
|
||||
print('❌ Geocoding fehlgeschlagen (Proxy): ${data['error']}');
|
||||
return data['fallbackLocation'] ??
|
||||
'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
}
|
||||
} else {
|
||||
print('⚠️ Proxy Response Status: ${response.statusCode}');
|
||||
return 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ Lokaler Proxy nicht erreichbar: $e');
|
||||
print('💡 Tipp: Starten Sie den Proxy mit: cd proxy-server && node server.js');
|
||||
return 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
}
|
||||
}
|
||||
// if (data['success'] == true) {
|
||||
// final location = data['location'] as String;
|
||||
// print('✅ Geocoding erfolgreich (Proxy): $location');
|
||||
// return location;
|
||||
// } else {
|
||||
// print('❌ Geocoding fehlgeschlagen (Proxy): ${data['error']}');
|
||||
// return data['fallbackLocation'] ??
|
||||
// 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
// }
|
||||
// } else {
|
||||
// print('⚠️ Proxy Response Status: ${response.statusCode}');
|
||||
// return 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print('❌ Lokaler Proxy nicht erreichbar: $e');
|
||||
// print('💡 Tipp: Starten Sie den Proxy mit: cd proxy-server && node server.js');
|
||||
// return 'Lat: ${lat.toStringAsFixed(6)}, Lon: ${lon.toStringAsFixed(6)}';
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user