Improve GPS performance and heading display
- Reduce GPS distanceFilter to 0 for faster updates - Add timeLimit to ensure regular position updates - Implement cached heading to avoid showing N/A when GPS heading unavailable - Add speed display logic: show "--" when stationary with no heading data - Add rotating navigation icon that points in heading direction - Fix degree symbol in heading format display 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+16
-5
@@ -3,11 +3,14 @@ import 'package:geolocator/geolocator.dart';
|
|||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class GpsService {
|
class GpsService {
|
||||||
|
static double? _lastValidHeading;
|
||||||
|
|
||||||
static Stream<Position> get positionStream {
|
static Stream<Position> get positionStream {
|
||||||
return Geolocator.getPositionStream(
|
return Geolocator.getPositionStream(
|
||||||
locationSettings: const LocationSettings(
|
locationSettings: const LocationSettings(
|
||||||
accuracy: LocationAccuracy.bestForNavigation,
|
accuracy: LocationAccuracy.bestForNavigation,
|
||||||
distanceFilter: 1,
|
distanceFilter: 0,
|
||||||
|
timeLimit: Duration(seconds: 10),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -21,16 +24,24 @@ class GpsService {
|
|||||||
return await Geolocator.isLocationServiceEnabled();
|
return await Geolocator.isLocationServiceEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double getCachedHeading(double heading) {
|
||||||
|
if (heading >= 0 && heading <= 360) {
|
||||||
|
_lastValidHeading = heading;
|
||||||
|
return heading;
|
||||||
|
}
|
||||||
|
return _lastValidHeading ?? 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
static String getCompassDirection(double heading) {
|
static String getCompassDirection(double heading) {
|
||||||
if (heading < 0) return 'N/A';
|
final cachedHeading = getCachedHeading(heading);
|
||||||
|
|
||||||
const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
|
const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
|
||||||
final index = ((heading + 22.5) / 45).floor() % 8;
|
final index = ((cachedHeading + 22.5) / 45).floor() % 8;
|
||||||
return directions[index];
|
return directions[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
static String formatHeading(double heading) {
|
static String formatHeading(double heading) {
|
||||||
if (heading < 0) return 'N/A';
|
final cachedHeading = getCachedHeading(heading);
|
||||||
return '${heading.round()} ${getCompassDirection(heading)}';
|
return '${cachedHeading.round()}° ${getCompassDirection(heading)}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-1
@@ -5,6 +5,7 @@ import 'package:wakelock_plus/wakelock_plus.dart';
|
|||||||
import 'speed_units.dart';
|
import 'speed_units.dart';
|
||||||
import 'gps_service.dart';
|
import 'gps_service.dart';
|
||||||
import 'color_themes.dart';
|
import 'color_themes.dart';
|
||||||
|
import 'dart:math' as math; // Import for math.pi
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const SpeedoApp());
|
runApp(const SpeedoApp());
|
||||||
@@ -118,10 +119,17 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _getSpeedDisplayText(double displaySpeed) {
|
||||||
|
if (_speed == 0.0 && _heading == -1.0) {
|
||||||
|
return '--';
|
||||||
|
}
|
||||||
|
return displaySpeed.toStringAsFixed(0);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final displaySpeed = _currentUnit.convert(_speed);
|
final displaySpeed = _currentUnit.convert(_speed);
|
||||||
final speedText = displaySpeed.toStringAsFixed(0);
|
final speedText = _getSpeedDisplayText(displaySpeed);
|
||||||
final currentTheme = ColorThemes.getTheme(_currentThemeIndex);
|
final currentTheme = ColorThemes.getTheme(_currentThemeIndex);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -222,12 +230,15 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Flexible(
|
Flexible(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
|
child: Transform.rotate(
|
||||||
|
angle: (_heading >= 0 && _heading < 360) ? (_heading * math.pi / 180.0) : 0,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.navigation,
|
Icons.navigation,
|
||||||
size: 100,
|
size: 100,
|
||||||
color: currentTheme.headingText,
|
color: currentTheme.headingText,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
|
|||||||
Reference in New Issue
Block a user