mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Implemented geocoding functionality to retrieve and manage device location data using the newly added geocoding
package.
This commit is contained in:
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user