Skip to content

Commit 334a648

Browse files
committed
perf(mobile): seed nav with last-known fix on Start ride
Tapping Start ride used to wait for the first live GPS tick before NavigationState emitted, which can take several seconds after a cold start. Fetch the cached last-known position (no GPS wait) and feed it into the Ferrostar controller before the live stream attaches, so the ETA sheet populates immediately and the live stream just keeps it fresh.
1 parent 00f430d commit 334a648

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

mobile/lib/navigation/navigation_service.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class NavigationService {
5050
Future<void> start({
5151
required WaypointInput origin,
5252
required WaypointInput destination,
53+
UserLocation? initialLocation,
5354
}) async {
5455
await dispose();
5556
_destination = destination;
@@ -60,6 +61,14 @@ class NavigationService {
6061
final waypoints = [origin, destination];
6162
_controller = await createController(routeJson, waypoints);
6263

64+
// Seed the controller with the last-known position before the live GPS
65+
// stream attaches, so NavigationState emits immediately instead of
66+
// waiting for the first fresh fix (which can take several seconds after
67+
// a cold start).
68+
if (initialLocation != null) {
69+
await _controller!.updateLocation(initialLocation);
70+
}
71+
6372
_stateSub = _controller!.stateStream.listen(
6473
_stateController.add,
6574
onError: _stateController.addError,

mobile/lib/screens/map_screen.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../models/location.dart';
1717
import '../models/route_preview.dart';
1818
import '../models/route_state.dart';
1919
import '../navigation/camera_controller.dart';
20+
import '../navigation/location_converter.dart';
2021
import '../navigation/maneuver_icons.dart';
2122
import '../navigation/nav_constants.dart';
2223
import '../providers/navigation_camera_provider.dart';
@@ -270,11 +271,19 @@ class _MapScreenState extends ConsumerState<MapScreen> {
270271
}
271272
debugPrint('nav: start ${origin.name} -> ${destination.name}');
272273
final service = ref.read(navigationServiceProvider);
274+
// Fetch last-known position synchronously (no GPS wait) so the controller
275+
// has an initial fix and NavigationState emits immediately.
276+
UserLocation? initial;
277+
try {
278+
final pos = await Geolocator.getLastKnownPosition();
279+
if (pos != null) initial = positionToUserLocation(pos);
280+
} catch (_) {}
273281
try {
274282
await service.start(
275283
origin: WaypointInput(lat: origin.lat, lng: origin.lng),
276284
destination:
277285
WaypointInput(lat: destination.lat, lng: destination.lng),
286+
initialLocation: initial,
278287
);
279288
} catch (e, st) {
280289
debugPrint('nav: start failed: $e\n$st');

0 commit comments

Comments
 (0)