Files
gps-speedo/lib/gps_service.dart
T
Mikkeli Matlock b185ce0999 feat: implement separate GPS timeouts and update project documentation
GPS Timeout Improvements:
- Add separate GPS timeouts: 20s for initial fix, 2s for ongoing updates
- Resolve indoor GPS timeout issues that caused stream termination
- Prevent GPS stream from stopping immediately due to aggressive timeouts
- Enhanced GPS manager initialization with initial position fetch

Documentation Updates:
- Update TODO.md with v2.3.0-dev architecture completion status
- Update CLAUDE.md with GPS manager architecture details
- Document clean data flow and separate timeout strategy
- Update branch strategy to reflect current development state

Technical Notes:
- GPS manager now handles initial cold start with long timeout
- Ongoing updates use shorter timeout for responsive behavior
- Architecture ready for intelligent caching logic implementation
- All overlay functionality preserved while improving GPS reliability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-31 14:53:29 +09:00

47 lines
1.5 KiB
Dart

import 'dart:async';
import 'package:geolocator/geolocator.dart';
import 'package:permission_handler/permission_handler.dart';
class GpsService {
static double? _lastValidHeading;
static Stream<Position> get positionStream {
return Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.bestForNavigation,
distanceFilter: 0,
timeLimit: Duration(seconds: 2), // Short timeout for ongoing updates after initial fix
),
);
}
static Future<bool> requestPermissions() async {
final permission = await Permission.locationWhenInUse.request();
return permission.isGranted;
}
static Future<bool> isLocationServiceEnabled() async {
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) {
final cachedHeading = getCachedHeading(heading);
const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
final index = ((cachedHeading + 22.5) / 45).floor() % 8;
return directions[index];
}
static String formatHeading(double heading) {
final cachedHeading = getCachedHeading(heading);
return '${cachedHeading.round()} ${getCompassDirection(heading)}'; // don't add that degree symbol, this is cooler
}
}