track_util.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:flutter_map/flutter_map.dart';
  2. import 'package:location/data/bean/atmob_track_point.dart';
  3. class TrackUtil {
  4. static List<TraceLocation> points2TraceLocation(
  5. List<AtmobTrackPoint>? pointsList) {
  6. if (pointsList == null) {
  7. return [];
  8. }
  9. List<TraceLocation> traceLocations = [];
  10. for (var value in pointsList) {
  11. TraceLocation traceLocation = TraceLocation(
  12. latitude: value.latitude,
  13. longitude: value.longitude,
  14. time: value.time,
  15. speed: value.speed,
  16. bearing: value.bearing,
  17. );
  18. traceLocations.add(traceLocation);
  19. }
  20. return traceLocations;
  21. }
  22. static List<LatLng> traceLocation2LatLng(
  23. List<TraceLocation>? traceLocations) {
  24. if (traceLocations == null) {
  25. return [];
  26. }
  27. return traceLocations
  28. .map((e) => LatLng(latitude: e.latitude, longitude: e.longitude))
  29. .toList();
  30. }
  31. static String formatDurationFromMillis(int milliseconds) {
  32. final totalMinutes = milliseconds ~/ 60000; // 毫秒转分钟
  33. final hours = totalMinutes ~/ 60;
  34. final minutes = totalMinutes % 60;
  35. if (hours > 0 && minutes > 0) {
  36. return '${hours}h${minutes}min';
  37. } else if (hours > 0) {
  38. return '${hours}h';
  39. } else {
  40. return '${minutes}min';
  41. }
  42. }
  43. static List<LatLng> getTrackMovePoints(
  44. List<AtmobTrackPoint>? pointsList, int startTime, int endTime) {
  45. if (pointsList == null || pointsList.isEmpty) {
  46. return [];
  47. }
  48. List<LatLng> movePoints = [];
  49. for (var point in pointsList) {
  50. if (point.time >= startTime && point.time <= endTime) {
  51. movePoints
  52. .add(LatLng(latitude: point.latitude, longitude: point.longitude));
  53. }
  54. }
  55. return movePoints;
  56. }
  57. static LatLng? getTrackStartPoint(
  58. List<AtmobTrackPoint>? pointsList, int startTime) {
  59. if (pointsList == null || pointsList.isEmpty) {
  60. return null;
  61. }
  62. for (var point in pointsList) {
  63. if (point.time >= startTime) {
  64. return LatLng(latitude: point.latitude, longitude: point.longitude);
  65. }
  66. }
  67. return null;
  68. }
  69. }