Implemented geocoding functionality to retrieve and manage device location data using the newly added geocoding package.

This commit is contained in:
Faris Armoush
2025-05-29 15:47:34 +03:00
parent 8ad048e18d
commit b6879035f0

View File

@ -0,0 +1,40 @@
import 'package:geocoding/geocoding.dart';
import 'package:syncrow_web/pages/analytics/models/device_location_info.dart';
import 'package:syncrow_web/pages/analytics/params/get_device_location_data_param.dart';
import 'package:syncrow_web/pages/analytics/services/device_location/device_location_service.dart';
class ReverseGeocodeDeviceLocationServiceDecorator implements DeviceLocationService {
const ReverseGeocodeDeviceLocationServiceDecorator(this._decoratee);
final DeviceLocationService _decoratee;
@override
Future<DeviceLocationInfo> get(GetDeviceLocationDataParam param) async {
try {
final deviceLocationInfo = await _decoratee.get(param);
final placemarks = await placemarkFromCoordinates(
param.latitude,
param.longitude,
);
if (placemarks.isNotEmpty) {
final place = placemarks.first;
final city = place.locality;
final country = place.country;
final address = place.street;
return deviceLocationInfo.copyWith(
city: city,
country: country,
address: address,
);
}
return deviceLocationInfo;
} catch (e) {
throw Exception('Failed to reverse load device location info');
}
}
}