File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import 'package:geolocator/geolocator.dart';
44UserLocation positionToUserLocation (Position p) => UserLocation (
55 lat: p.latitude,
66 lng: p.longitude,
7- horizontalAccuracyM: p.accuracy,
8- courseDeg: p.heading > 0 ? p.heading : null ,
9- speedMps: p.speed,
7+ horizontalAccuracyM: p.accuracy >= 0 ? p.accuracy : 0 ,
8+ courseDeg: p.heading >= 0 ? p.heading : null ,
9+ speedMps: p.speed >= 0 ? p.speed : null ,
1010 timestampMs: p.timestamp.millisecondsSinceEpoch,
1111 );
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ void main() {
2929 expect (result.timestampMs, 1000 );
3030 });
3131
32- test ('sets courseDeg to null when heading is zero ' , () {
32+ test ('preserves heading=0 (due north) as courseDeg 0.0 ' , () {
3333 final pos = Position (
3434 latitude: 52.52 ,
3535 longitude: 13.405 ,
@@ -45,6 +45,26 @@ void main() {
4545
4646 final result = positionToUserLocation (pos);
4747
48+ expect (result.courseDeg, 0.0 );
49+ });
50+
51+ test ('sets courseDeg/speedMps to null when geolocator returns -1 sentinel' , () {
52+ final pos = Position (
53+ latitude: 52.52 ,
54+ longitude: 13.405 ,
55+ accuracy: 5 ,
56+ heading: - 1.0 ,
57+ speed: - 1.0 ,
58+ timestamp: DateTime .fromMillisecondsSinceEpoch (0 ),
59+ altitude: 0 ,
60+ altitudeAccuracy: 0 ,
61+ headingAccuracy: 0 ,
62+ speedAccuracy: 0 ,
63+ );
64+
65+ final result = positionToUserLocation (pos);
66+
4867 expect (result.courseDeg, isNull);
68+ expect (result.speedMps, isNull);
4969 });
5070}
You can’t perform that action at this time.
0 commit comments