feat: Enhance geofence functionality with new status banners and utility functions
This commit is contained in:
@@ -5,6 +5,7 @@ export 'src/core_module.dart';
|
||||
export 'src/domain/arguments/usecase_argument.dart';
|
||||
export 'src/domain/usecases/usecase.dart';
|
||||
export 'src/utils/date_time_utils.dart';
|
||||
export 'src/utils/geo_utils.dart';
|
||||
export 'src/presentation/widgets/web_mobile_frame.dart';
|
||||
export 'src/presentation/mixins/bloc_error_handler.dart';
|
||||
export 'src/presentation/observers/core_bloc_observer.dart';
|
||||
|
||||
32
apps/mobile/packages/core/lib/src/utils/geo_utils.dart
Normal file
32
apps/mobile/packages/core/lib/src/utils/geo_utils.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'dart:math';
|
||||
|
||||
/// Calculates the distance in meters between two geographic coordinates
|
||||
/// using the Haversine formula.
|
||||
double calculateDistance(
|
||||
double lat1,
|
||||
double lng1,
|
||||
double lat2,
|
||||
double lng2,
|
||||
) {
|
||||
const double earthRadius = 6371000.0;
|
||||
final double dLat = _toRadians(lat2 - lat1);
|
||||
final double dLng = _toRadians(lng2 - lng1);
|
||||
final double a = sin(dLat / 2) * sin(dLat / 2) +
|
||||
cos(_toRadians(lat1)) *
|
||||
cos(_toRadians(lat2)) *
|
||||
sin(dLng / 2) *
|
||||
sin(dLng / 2);
|
||||
final double c = 2 * atan2(sqrt(a), sqrt(1 - a));
|
||||
return earthRadius * c;
|
||||
}
|
||||
|
||||
/// Formats a distance in meters to a human-readable string.
|
||||
String formatDistance(double meters) {
|
||||
if (meters >= 1000) {
|
||||
return '${(meters / 1000).toStringAsFixed(1)} km';
|
||||
}
|
||||
return '${meters.round()} m';
|
||||
}
|
||||
|
||||
/// Converts degrees to radians.
|
||||
double _toRadians(double degrees) => degrees * pi / 180;
|
||||
Reference in New Issue
Block a user