From 8a6edda21f2228e8ddd704e248ceb348a95bfa57 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Mon, 30 Oct 2023 16:11:50 +0100 Subject: [PATCH 01/16] Added satelliteCount and satellitesUsedInFix to Android --- geolocator/test/geolocator_test.dart | 6 ++++- geolocator_android/CHANGELOG.md | 4 +++ .../geolocator/location/LocationMapper.java | 16 ++++++++--- .../geolocator/location/NmeaClient.java | 26 ++++++++++++++++++ geolocator_android/pubspec.yaml | 2 +- .../test/geolocator_android_test.dart | 27 ++++++++++--------- geolocator_platform_interface/CHANGELOG.md | 4 +++ .../lib/src/models/position.dart | 22 +++++++++++++++ geolocator_platform_interface/pubspec.yaml | 2 +- 9 files changed, 90 insertions(+), 19 deletions(-) diff --git a/geolocator/test/geolocator_test.dart b/geolocator/test/geolocator_test.dart index 185a0d48..23deacb1 100644 --- a/geolocator/test/geolocator_test.dart +++ b/geolocator/test/geolocator_test.dart @@ -12,10 +12,14 @@ Position get mockPosition => Position( isUtc: true, ), altitude: 3000.0, + satelliteCount: 3.0, + satellitesUsedInFix: 2.0, accuracy: 0.0, heading: 0.0, speed: 0.0, - speedAccuracy: 0.0); + speedAccuracy: 0.0, + altitudeAccuracy: 0.0, + headingAccuracy: 0.0); void main() { group('Geolocator', () { diff --git a/geolocator_android/CHANGELOG.md b/geolocator_android/CHANGELOG.md index d678b582..714b3072 100644 --- a/geolocator_android/CHANGELOG.md +++ b/geolocator_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.3.0 + +* Adds the `gnss_satellite_count` and `gnss_satellites_used_in_fix` properties from the GNSS status callback to the Android platform. + ## 4.2.2 * Adds back the `applicationId` property of the AndroidManifest.xml file to keep backwardscompatibility with older applications that still rely on Gradle version <7.0. diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java index a9ac9ac2..bed12718 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java @@ -27,10 +27,18 @@ public static Map toHashMap(Location location) { position.put("speed_accuracy", (double) location.getSpeedAccuracyMetersPerSecond()); if (location.getExtras() != null) { - if (location.getExtras().containsKey(NmeaClient.NMEA_ALTITUDE_EXTRA)) { - Double mslAltitude = location.getExtras().getDouble(NmeaClient.NMEA_ALTITUDE_EXTRA); - position.put("altitude", mslAltitude); - } + if (location.getExtras().containsKey(NmeaClient.NMEA_ALTITUDE_EXTRA)) { + Double mslAltitude = location.getExtras().getDouble(NmeaClient.NMEA_ALTITUDE_EXTRA); + position.put("altitude", mslAltitude); + } + if (location.getExtras().containsKey(NmeaClient.GNSS_SATELLITE_COUNT_EXTRA)) { + Double mslSatelliteCount = location.getExtras().getDouble(NmeaClient.GNSS_SATELLITE_COUNT_EXTRA); + position.put("gnss_satellite_count", mslSatelliteCount); + } + if (location.getExtras().containsKey(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA)) { + Double mslSatellitesUsedInFix = location.getExtras().getDouble(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA); + position.put("gnss_satellites_used_in_fix", mslSatellitesUsedInFix); + } } return position; } diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java index 497f7df3..eb1fe249 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java @@ -3,6 +3,7 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; +import android.location.GnssStatus; import android.location.Location; import android.location.LocationManager; import android.location.OnNmeaMessageListener; @@ -17,6 +18,8 @@ public class NmeaClient { public static final String NMEA_ALTITUDE_EXTRA = "geolocator_mslAltitude"; + public static final String GNSS_SATELLITE_COUNT_EXTRA = "geolocator_mslSatelliteCount"; + public static final String GNSS_SATELLITES_USED_IN_FIX_EXTRA = "geolocator_mslSatellitesUsedInFix"; private final Context context; private final LocationManager locationManager; @@ -24,8 +27,12 @@ public class NmeaClient { @TargetApi(Build.VERSION_CODES.N) private OnNmeaMessageListener nmeaMessageListener; + @TargetApi(Build.VERSION_CODES.N) + private GnssStatus.Callback gnssCallback; private String lastNmeaMessage; + private double gnss_satellite_count; + private double gnss_satellites_used_in_fix; @Nullable private Calendar lastNmeaMessageTime; private boolean listenerAdded = false; @@ -42,6 +49,17 @@ public NmeaClient(@NonNull Context context, @Nullable LocationOptions locationOp lastNmeaMessageTime = Calendar.getInstance(); } }; + + gnssCallback = new GnssStatus.Callback() { + @Override + public void onSatelliteStatusChanged(@NonNull GnssStatus status) { + gnss_satellite_count = status.getSatelliteCount(); + gnss_satellites_used_in_fix = 0; + for (int i = 0; i < gnss_satellite_count; ++i) + if (status.usedInFix(i)) + ++gnss_satellites_used_in_fix; + } + }; } } @@ -54,6 +72,7 @@ public void start() { if (locationOptions != null && locationOptions.isUseMSLAltitude()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) { locationManager.addNmeaListener(nmeaMessageListener, null); + locationManager.registerGnssStatusCallback(gnssCallback, null); listenerAdded = true; } } @@ -63,6 +82,7 @@ public void stop() { if (locationOptions != null && locationOptions.isUseMSLAltitude()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) { locationManager.removeNmeaListener(nmeaMessageListener); + locationManager.unregisterGnssStatusCallback(gnssCallback); listenerAdded = false; } } @@ -74,6 +94,12 @@ public void enrichExtrasWithNmea(@Nullable Location location) { return; } + if (location.getExtras() == null) { + location.setExtras(Bundle.EMPTY); + } + location.getExtras().putDouble(GNSS_SATELLITE_COUNT_EXTRA, gnss_satellite_count); + location.getExtras().putDouble(GNSS_SATELLITES_USED_IN_FIX_EXTRA, gnss_satellites_used_in_fix); + if (lastNmeaMessage != null && locationOptions != null && listenerAdded) { Calendar expiryDate = Calendar.getInstance(); diff --git a/geolocator_android/pubspec.yaml b/geolocator_android/pubspec.yaml index a986d009..c44602eb 100644 --- a/geolocator_android/pubspec.yaml +++ b/geolocator_android/pubspec.yaml @@ -2,7 +2,7 @@ name: geolocator_android description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator. repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen -version: 4.2.2 +version: 4.3.0 environment: sdk: ">=2.15.0 <4.0.0" diff --git a/geolocator_android/test/geolocator_android_test.dart b/geolocator_android/test/geolocator_android_test.dart index 17599b0e..c44e5479 100644 --- a/geolocator_android/test/geolocator_android_test.dart +++ b/geolocator_android/test/geolocator_android_test.dart @@ -9,18 +9,21 @@ import 'event_channel_mock.dart'; import 'method_channel_mock.dart'; Position get mockPosition => Position( - latitude: 52.561270, - longitude: 5.639382, - timestamp: DateTime.fromMillisecondsSinceEpoch( - 500, - isUtc: true, - ), - altitude: 3000.0, - accuracy: 0.0, - heading: 0.0, - speed: 0.0, - speedAccuracy: 0.0, - isMocked: false); + latitude: 52.561270, + longitude: 5.639382, + timestamp: DateTime.fromMillisecondsSinceEpoch( + 500, + isUtc: true, + ), + altitude: 3000.0, + satelliteCount: 2.0, + satellitesUsedInFix: 2.0, + accuracy: 0.0, + heading: 0.0, + speed: 0.0, + speedAccuracy: 0.0, + isMocked: false, + ); void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/geolocator_platform_interface/CHANGELOG.md b/geolocator_platform_interface/CHANGELOG.md index 5fbd9ea6..92cf27aa 100644 --- a/geolocator_platform_interface/CHANGELOG.md +++ b/geolocator_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.0 + +- Added satellite count and satellite used in fix. + ## 4.0.7 - Fixed a spelling error in docs. diff --git a/geolocator_platform_interface/lib/src/models/position.dart b/geolocator_platform_interface/lib/src/models/position.dart index 822fac3b..35a20d32 100644 --- a/geolocator_platform_interface/lib/src/models/position.dart +++ b/geolocator_platform_interface/lib/src/models/position.dart @@ -12,6 +12,8 @@ class Position { required this.timestamp, required this.accuracy, required this.altitude, + required this.satelliteCount, + required this.satellitesUsedInFix, required this.heading, required this.speed, required this.speedAccuracy, @@ -36,6 +38,18 @@ class Position { /// value is 0.0. final double altitude; + /// On Android: if available it resturns the number of GNSS satellites. + /// On other platforms: the number of satellites is not available. + /// + /// If the number of satellites is not available it returns the default value: 0.0. + final double satelliteCount; + + /// On Android: if available it returns the number of GNSS satellites used in fix. + /// On other platforms: the number of satellites used in fix is not available. + /// + /// If the number of satellites used in fix is not available it returns the default value: 0.0. + final double satellitesUsedInFix; + /// The estimated horizontal accuracy of the position in meters. /// /// The accuracy is not available on all devices. In these cases the value is @@ -79,6 +93,8 @@ class Position { var areEqual = other is Position && other.accuracy == accuracy && other.altitude == altitude && + other.satelliteCount == satelliteCount && + other.satellitesUsedInFix == satellitesUsedInFix && other.heading == heading && other.latitude == latitude && other.longitude == longitude && @@ -95,6 +111,8 @@ class Position { int get hashCode => accuracy.hashCode ^ altitude.hashCode ^ + satelliteCount.hashCode ^ + satellitesUsedInFix.hashCode ^ heading.hashCode ^ latitude.hashCode ^ longitude.hashCode ^ @@ -133,6 +151,8 @@ class Position { longitude: positionMap['longitude'], timestamp: timestamp, altitude: positionMap['altitude'] ?? 0.0, + satelliteCount: positionMap['gnss_satellite_count'] ?? 0.0, + satellitesUsedInFix: positionMap['gnss_satellites_used_in_fix'] ?? 0.0, accuracy: positionMap['accuracy'] ?? 0.0, heading: positionMap['heading'] ?? 0.0, floor: positionMap['floor'], @@ -150,6 +170,8 @@ class Position { 'timestamp': timestamp?.millisecondsSinceEpoch, 'accuracy': accuracy, 'altitude': altitude, + 'gnss_satellite_count': satelliteCount, + 'gnss_satellites_used_in_fix': satellitesUsedInFix, 'floor': floor, 'heading': heading, 'speed': speed, diff --git a/geolocator_platform_interface/pubspec.yaml b/geolocator_platform_interface/pubspec.yaml index 007968da..fe5fe28a 100644 --- a/geolocator_platform_interface/pubspec.yaml +++ b/geolocator_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the geolocator plugin. repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 4.0.7 +version: 4.1.0 dependencies: flutter: From 26489cc518b083b7be8455a9cba831f56c68916a Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Mon, 30 Oct 2023 16:53:07 +0100 Subject: [PATCH 02/16] changed the text of the Changelog --- geolocator_platform_interface/CHANGELOG.md | 2 +- geolocator_platform_interface/lib/src/models/position.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geolocator_platform_interface/CHANGELOG.md b/geolocator_platform_interface/CHANGELOG.md index 92cf27aa..6f1fb6bd 100644 --- a/geolocator_platform_interface/CHANGELOG.md +++ b/geolocator_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.1.0 -- Added satellite count and satellite used in fix. +- Added `satelliteCount` and `satellitesUsedInFix` to `Position`. ## 4.0.7 diff --git a/geolocator_platform_interface/lib/src/models/position.dart b/geolocator_platform_interface/lib/src/models/position.dart index 35a20d32..3ac82ccf 100644 --- a/geolocator_platform_interface/lib/src/models/position.dart +++ b/geolocator_platform_interface/lib/src/models/position.dart @@ -38,7 +38,7 @@ class Position { /// value is 0.0. final double altitude; - /// On Android: if available it resturns the number of GNSS satellites. + /// On Android: if available it returns the number of GNSS satellites. /// On other platforms: the number of satellites is not available. /// /// If the number of satellites is not available it returns the default value: 0.0. From 655ca9f79033b8f32482a1cf39ae4dd971050225 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Wed, 1 Nov 2023 11:24:06 +0100 Subject: [PATCH 03/16] Created a AndroidPosition object with Android specific parameters. --- geolocator/lib/geolocator.dart | 5 +- geolocator/pubspec.yaml | 2 +- geolocator/test/geolocator_test.dart | 2 - geolocator_android/CHANGELOG.md | 3 +- .../lib/geolocator_android.dart | 1 + .../lib/src/geolocator_android.dart | 7 +- .../lib/src/types/android_position.dart | 99 +++++++++++++++++++ geolocator_android/pubspec.yaml | 2 +- .../test/geolocator_android_test.dart | 2 +- .../lib/src/models/position.dart | 29 ++---- .../method_channel_geolocator_test.dart | 29 +++--- .../test/src/models/position_test.dart | 41 +++++++- geolocator_web/lib/src/utils.dart | 29 +++--- 13 files changed, 185 insertions(+), 66 deletions(-) create mode 100644 geolocator_android/lib/src/types/android_position.dart diff --git a/geolocator/lib/geolocator.dart b/geolocator/lib/geolocator.dart index 86311aa7..f1f3849d 100644 --- a/geolocator/lib/geolocator.dart +++ b/geolocator/lib/geolocator.dart @@ -1,12 +1,9 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:geolocator_android/geolocator_android.dart'; import 'package:geolocator_apple/geolocator_apple.dart'; +import 'package:geolocator_android/geolocator_android.dart'; import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; - -export 'package:geolocator_android/geolocator_android.dart' - show AndroidSettings, ForegroundNotificationConfig, AndroidResource; export 'package:geolocator_apple/geolocator_apple.dart' show AppleSettings, ActivityType; export 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; diff --git a/geolocator/pubspec.yaml b/geolocator/pubspec.yaml index bfbf5e7c..3ca5174c 100644 --- a/geolocator/pubspec.yaml +++ b/geolocator/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: sdk: flutter geolocator_platform_interface: ^4.1.0 - geolocator_android: ^4.3.0 + geolocator_android: ^4.4.0 geolocator_apple: ^2.3.0 geolocator_web: ^2.2.0 geolocator_windows: ^0.2.2 diff --git a/geolocator/test/geolocator_test.dart b/geolocator/test/geolocator_test.dart index 064fa210..59099a9f 100644 --- a/geolocator/test/geolocator_test.dart +++ b/geolocator/test/geolocator_test.dart @@ -13,8 +13,6 @@ Position get mockPosition => Position( ), altitude: 3000.0, altitudeAccuracy: 0.0, - satelliteCount: 3.0, - satellitesUsedInFix: 2.0, accuracy: 0.0, heading: 0.0, headingAccuracy: 0.0, diff --git a/geolocator_android/CHANGELOG.md b/geolocator_android/CHANGELOG.md index a72ecd27..31085d5c 100644 --- a/geolocator_android/CHANGELOG.md +++ b/geolocator_android/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.4.0 -* Adds the `gnss_satellite_count` and `gnss_satellites_used_in_fix` properties from the GNSS status callback to the Android platform. +* Creates `AndroidPosition`, a child class of `Position` with Android specific properties. +* Adds the `satelliteCount` and `satellitesUsedInFix` to `AndroidPosition`. ## 4.3.3 diff --git a/geolocator_android/lib/geolocator_android.dart b/geolocator_android/lib/geolocator_android.dart index 4bdbfcf8..c15a7c21 100644 --- a/geolocator_android/lib/geolocator_android.dart +++ b/geolocator_android/lib/geolocator_android.dart @@ -17,5 +17,6 @@ export 'package:geolocator_platform_interface/geolocator_platform_interface.dart export 'src/geolocator_android.dart'; export 'src/types/android_settings.dart' show AndroidSettings; +export 'src/types/android_position.dart' show AndroidPosition; export 'src/types/foreground_settings.dart' show AndroidResource, ForegroundNotificationConfig; diff --git a/geolocator_android/lib/src/geolocator_android.dart b/geolocator_android/lib/src/geolocator_android.dart index 8ebad88b..04c1ced8 100644 --- a/geolocator_android/lib/src/geolocator_android.dart +++ b/geolocator_android/lib/src/geolocator_android.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; +import 'package:geolocator_android/geolocator_android.dart'; import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; import 'package:uuid/uuid.dart'; @@ -83,7 +84,7 @@ class GeolocatorAndroid extends GeolocatorPlatform { final positionMap = await _methodChannel.invokeMethod('getLastKnownPosition', parameters); - return positionMap != null ? Position.fromMap(positionMap) : null; + return positionMap != null ? AndroidPosition.fromMap(positionMap) : null; } on PlatformException catch (e) { final error = _handlePlatformException(e); @@ -123,7 +124,7 @@ class GeolocatorAndroid extends GeolocatorPlatform { } final positionMap = await positionFuture; - return Position.fromMap(positionMap); + return AndroidPosition.fromMap(positionMap); } on TimeoutException { final parameters = { 'requestId': requestId, @@ -191,7 +192,7 @@ class GeolocatorAndroid extends GeolocatorPlatform { _positionStream = positionStream .map((dynamic element) => - Position.fromMap(element.cast())) + AndroidPosition.fromMap(element.cast())) .handleError( (error) { if (error is PlatformException) { diff --git a/geolocator_android/lib/src/types/android_position.dart b/geolocator_android/lib/src/types/android_position.dart new file mode 100644 index 00000000..562059dc --- /dev/null +++ b/geolocator_android/lib/src/types/android_position.dart @@ -0,0 +1,99 @@ +import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; +// ignore: depend_on_referenced_packages +import 'package:meta/meta.dart'; + +/// Contains additional location information only available on Android platforms. +@immutable +class AndroidPosition extends Position { + /// Constructs an instance with the given values for testing. [AndroidPosition] + /// instances constructed this way won't actually reflect any real information + /// from the platform, just whatever was passed in at construction time. + const AndroidPosition( + {required this.satelliteCount, + required this.satellitesUsedInFix, + required longitude, + required latitude, + required timestamp, + required accuracy, + required altitude, + required altitudeAccuracy, + required heading, + required headingAccuracy, + required speed, + required speedAccuracy, + int? floor, + isMocked = false}) + : super( + longitude: longitude, + latitude: latitude, + timestamp: timestamp, + accuracy: accuracy, + altitude: 0.0, + altitudeAccuracy: 0.0, + heading: 0.0, + headingAccuracy: 0.0, + speed: 0.0, + speedAccuracy: 0.0); + + /// If available it returns the number of GNSS satellites. + /// + /// If the number of satellites is not available it returns the default value: 0.0. + final double satelliteCount; + + /// If available it returns the number of GNSS satellites used in fix. + /// + /// If the number of satellites used in fix is not available it returns the default value: 0.0. + final double satellitesUsedInFix; + + @override + bool operator ==(Object other) { + var areEqual = other is AndroidPosition && + other.satelliteCount == satelliteCount && + other.satellitesUsedInFix == satellitesUsedInFix; + return areEqual; + } + + @override + String toString() { + return 'Latitude: $latitude, Longitude: $longitude, Satellite count: $satelliteCount, Satellites used in fix: $satellitesUsedInFix'; + } + + @override + int get hashCode => satelliteCount.hashCode ^ satellitesUsedInFix.hashCode; + + /// Converts the supplied [Map] to an instance of the [AndroidPosition] class. + + static AndroidPosition fromMap(dynamic message) { + final Map positionMap = message; + + return AndroidPosition( + satelliteCount: positionMap['gnss_satellite_count'] ?? 0.0, + satellitesUsedInFix: positionMap['gnss_satellites_used_in_fix'] ?? 0.0, + latitude: positionMap['latitude'], + longitude: positionMap['longitude'], + timestamp: DateTime.fromMillisecondsSinceEpoch( + positionMap['timestamp'].toInt(), + isUtc: true), + altitude: positionMap['altitude'] ?? 0.0, + altitudeAccuracy: positionMap['altitude_accuracy'] ?? 0.0, + accuracy: positionMap['accuracy'] ?? 0.0, + heading: positionMap['heading'] ?? 0.0, + headingAccuracy: positionMap['heading_accuracy'] ?? 0.0, + floor: positionMap['floor'], + speed: positionMap['speed'] ?? 0.0, + speedAccuracy: positionMap['speed_accuracy'] ?? 0.0, + isMocked: positionMap['is_mocked'] ?? false, + ); + } + + /// Converts the [AndroidPosition] instance into a [Map] instance that can be + /// serialized to JSON. + @override + Map toJson() { + return super.toJson() + ..addAll({ + 'gnss_satellite_count': satelliteCount, + 'gnss_satellites_used_in_fix': satellitesUsedInFix, + }); + } +} diff --git a/geolocator_android/pubspec.yaml b/geolocator_android/pubspec.yaml index 5f3b559c..908e6ae5 100644 --- a/geolocator_android/pubspec.yaml +++ b/geolocator_android/pubspec.yaml @@ -20,7 +20,7 @@ flutter: dependencies: flutter: sdk: flutter - geolocator_platform_interface: ^4.2.0 + geolocator_platform_interface: ^4.1.1 uuid: ^4.1.0 dev_dependencies: diff --git a/geolocator_android/test/geolocator_android_test.dart b/geolocator_android/test/geolocator_android_test.dart index 7ebe514b..929caf25 100644 --- a/geolocator_android/test/geolocator_android_test.dart +++ b/geolocator_android/test/geolocator_android_test.dart @@ -8,7 +8,7 @@ import 'package:geolocator_android/geolocator_android.dart'; import 'event_channel_mock.dart'; import 'method_channel_mock.dart'; -Position get mockPosition => Position( +Position get mockPosition => AndroidPosition( latitude: 52.561270, longitude: 5.639382, timestamp: DateTime.fromMillisecondsSinceEpoch( diff --git a/geolocator_platform_interface/lib/src/models/position.dart b/geolocator_platform_interface/lib/src/models/position.dart index afbc05e9..4b8b45a5 100644 --- a/geolocator_platform_interface/lib/src/models/position.dart +++ b/geolocator_platform_interface/lib/src/models/position.dart @@ -13,8 +13,6 @@ class Position { required this.accuracy, required this.altitude, required this.altitudeAccuracy, - required this.satelliteCount, - required this.satellitesUsedInFix, required this.heading, required this.headingAccuracy, required this.speed, @@ -46,18 +44,6 @@ class Position { /// 0.0. final double altitudeAccuracy; - /// On Android: if available it returns the number of GNSS satellites. - /// On other platforms: the number of satellites is not available. - /// - /// If the number of satellites is not available it returns the default value: 0.0. - final double satelliteCount; - - /// On Android: if available it returns the number of GNSS satellites used in fix. - /// On other platforms: the number of satellites used in fix is not available. - /// - /// If the number of satellites used in fix is not available it returns the default value: 0.0. - final double satellitesUsedInFix; - /// The estimated horizontal accuracy of the position in meters. /// /// The accuracy is not available on all devices. In these cases the value is @@ -108,8 +94,6 @@ class Position { other.accuracy == accuracy && other.altitude == altitude && other.altitudeAccuracy == altitudeAccuracy && - other.satelliteCount == satelliteCount && - other.satellitesUsedInFix == satellitesUsedInFix && other.heading == heading && other.headingAccuracy == headingAccuracy && other.latitude == latitude && @@ -128,8 +112,6 @@ class Position { accuracy.hashCode ^ altitude.hashCode ^ altitudeAccuracy.hashCode ^ - satelliteCount.hashCode ^ - satellitesUsedInFix.hashCode ^ heading.hashCode ^ headingAccuracy.hashCode ^ latitude.hashCode ^ @@ -169,9 +151,10 @@ class Position { longitude: positionMap['longitude'], timestamp: timestamp, altitude: positionMap['altitude'] ?? 0.0, - altitudeAccuracy: positionMap['altitude_accuracy'] ?? 0.0, - satelliteCount: positionMap['gnss_satellite_count'] ?? 0.0, - satellitesUsedInFix: positionMap['gnss_satellites_used_in_fix'] ?? 0.0, + // androidPosition: AndroidPosition( + // satelliteCount: positionMap['gnss_satellite_count'] ?? 0.0, + // satellitesUsedInFix: + // positionMap['gnss_satellites_used_in_fix'] ?? 0.0), accuracy: positionMap['accuracy'] ?? 0.0, heading: positionMap['heading'] ?? 0.0, headingAccuracy: positionMap['heading_accuracy'] ?? 0.0, @@ -179,6 +162,7 @@ class Position { speed: positionMap['speed'] ?? 0.0, speedAccuracy: positionMap['speed_accuracy'] ?? 0.0, isMocked: positionMap['is_mocked'] ?? false, + altitudeAccuracy: positionMap['altitude_accuracy'] ?? 0.0, ); } @@ -191,8 +175,7 @@ class Position { 'accuracy': accuracy, 'altitude': altitude, 'altitude_accuracy': altitudeAccuracy, - 'gnss_satellite_count': satelliteCount, - 'gnss_satellites_used_in_fix': satellitesUsedInFix, + // 'android_position': androidPosition, 'floor': floor, 'heading': heading, 'heading_accuracy': headingAccuracy, diff --git a/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart b/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart index b313a0ce..1ad99ce9 100644 --- a/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart +++ b/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart @@ -10,20 +10,21 @@ import 'event_channel_mock.dart'; import 'method_channel_mock.dart'; Position get mockPosition => Position( - latitude: 52.561270, - longitude: 5.639382, - timestamp: DateTime.fromMillisecondsSinceEpoch( - 500, - isUtc: true, - ), - altitude: 3000.0, - altitudeAccuracy: 2.0, - accuracy: 0.0, - heading: 0.0, - headingAccuracy: 0.0, - speed: 0.0, - speedAccuracy: 0.0, - isMocked: false); + latitude: 52.561270, + longitude: 5.639382, + timestamp: DateTime.fromMillisecondsSinceEpoch( + 500, + isUtc: true, + ), + altitude: 3000.0, + altitudeAccuracy: 2.0, + accuracy: 0.0, + heading: 0.0, + headingAccuracy: 0.0, + speed: 0.0, + speedAccuracy: 0.0, + isMocked: false, + ); void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/geolocator_platform_interface/test/src/models/position_test.dart b/geolocator_platform_interface/test/src/models/position_test.dart index 265429d7..a37de329 100644 --- a/geolocator_platform_interface/test/src/models/position_test.dart +++ b/geolocator_platform_interface/test/src/models/position_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer_const_constructors + import 'package:flutter_test/flutter_test.dart'; import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; @@ -449,6 +451,44 @@ void main() { ); }); + test( + 'hashCode should not match when the androidPosition property is different', + () { + // Arrange + final firstPosition = Position( + longitude: 0, + latitude: 0, + timestamp: DateTime.fromMillisecondsSinceEpoch(0), + accuracy: 0, + altitude: 0, + altitudeAccuracy: 0, + heading: 0, + headingAccuracy: 0, + speed: 0, + speedAccuracy: 0, + isMocked: true, + ); + final secondPosition = Position( + longitude: 0, + latitude: 0, + timestamp: DateTime.fromMillisecondsSinceEpoch(0), + accuracy: 0, + altitude: 0, + altitudeAccuracy: 0, + heading: 0, + headingAccuracy: 0, + speed: 0, + speedAccuracy: 0, + isMocked: true, + ); + + // Act & Assert + expect( + firstPosition.hashCode != secondPosition.hashCode, + true, + ); + }); + test('hashCode should not match when the floor property is different', () { // Arrange final firstPosition = Position( @@ -530,7 +570,6 @@ void main() { speedAccuracy: 0, isMocked: false, ); - // Act final readablePosition = position.toString(); diff --git a/geolocator_web/lib/src/utils.dart b/geolocator_web/lib/src/utils.dart index cd50aee5..ca6c7b36 100644 --- a/geolocator_web/lib/src/utils.dart +++ b/geolocator_web/lib/src/utils.dart @@ -12,21 +12,20 @@ Position toPosition(html.Geoposition webPosition) { } return Position( - latitude: coords.latitude as double, - longitude: coords.longitude as double, - timestamp: webPosition.timestamp != null - ? DateTime.fromMillisecondsSinceEpoch(webPosition.timestamp!) - : DateTime.now(), - altitude: coords.altitude as double? ?? 0.0, - altitudeAccuracy: coords.altitudeAccuracy as double? ?? 0.0, - accuracy: coords.accuracy as double? ?? 0.0, - heading: coords.heading as double? ?? 0.0, - headingAccuracy: 0.0, - floor: null, - speed: coords.speed as double? ?? 0.0, - speedAccuracy: 0.0, - isMocked: false, - ); + latitude: coords.latitude as double, + longitude: coords.longitude as double, + timestamp: webPosition.timestamp != null + ? DateTime.fromMillisecondsSinceEpoch(webPosition.timestamp!) + : DateTime.now(), + altitude: coords.altitude as double? ?? 0.0, + altitudeAccuracy: coords.altitudeAccuracy as double? ?? 0.0, + accuracy: coords.accuracy as double? ?? 0.0, + heading: coords.heading as double? ?? 0.0, + headingAccuracy: 0.0, + floor: null, + speed: coords.speed as double? ?? 0.0, + speedAccuracy: 0.0, + isMocked: false); } /// Converts the permission result received from the browser into a From 49379e1fdb6d7c24f088bcce550bee22579473cd Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Wed, 1 Nov 2023 16:34:32 +0100 Subject: [PATCH 04/16] fixed test --- .../lib/src/models/position.dart | 5 --- .../test/src/models/position_test.dart | 38 ------------------- 2 files changed, 43 deletions(-) diff --git a/geolocator_platform_interface/lib/src/models/position.dart b/geolocator_platform_interface/lib/src/models/position.dart index 4b8b45a5..7f727ace 100644 --- a/geolocator_platform_interface/lib/src/models/position.dart +++ b/geolocator_platform_interface/lib/src/models/position.dart @@ -151,10 +151,6 @@ class Position { longitude: positionMap['longitude'], timestamp: timestamp, altitude: positionMap['altitude'] ?? 0.0, - // androidPosition: AndroidPosition( - // satelliteCount: positionMap['gnss_satellite_count'] ?? 0.0, - // satellitesUsedInFix: - // positionMap['gnss_satellites_used_in_fix'] ?? 0.0), accuracy: positionMap['accuracy'] ?? 0.0, heading: positionMap['heading'] ?? 0.0, headingAccuracy: positionMap['heading_accuracy'] ?? 0.0, @@ -175,7 +171,6 @@ class Position { 'accuracy': accuracy, 'altitude': altitude, 'altitude_accuracy': altitudeAccuracy, - // 'android_position': androidPosition, 'floor': floor, 'heading': heading, 'heading_accuracy': headingAccuracy, diff --git a/geolocator_platform_interface/test/src/models/position_test.dart b/geolocator_platform_interface/test/src/models/position_test.dart index a37de329..53252ceb 100644 --- a/geolocator_platform_interface/test/src/models/position_test.dart +++ b/geolocator_platform_interface/test/src/models/position_test.dart @@ -451,44 +451,6 @@ void main() { ); }); - test( - 'hashCode should not match when the androidPosition property is different', - () { - // Arrange - final firstPosition = Position( - longitude: 0, - latitude: 0, - timestamp: DateTime.fromMillisecondsSinceEpoch(0), - accuracy: 0, - altitude: 0, - altitudeAccuracy: 0, - heading: 0, - headingAccuracy: 0, - speed: 0, - speedAccuracy: 0, - isMocked: true, - ); - final secondPosition = Position( - longitude: 0, - latitude: 0, - timestamp: DateTime.fromMillisecondsSinceEpoch(0), - accuracy: 0, - altitude: 0, - altitudeAccuracy: 0, - heading: 0, - headingAccuracy: 0, - speed: 0, - speedAccuracy: 0, - isMocked: true, - ); - - // Act & Assert - expect( - firstPosition.hashCode != secondPosition.hashCode, - true, - ); - }); - test('hashCode should not match when the floor property is different', () { // Arrange final firstPosition = Position( From b9c5e12f4ae6f36a86024a6238cc6901369dabe0 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Thu, 2 Nov 2023 09:23:57 +0100 Subject: [PATCH 05/16] cleanup --- geolocator/lib/geolocator.dart | 3 +++ geolocator/pubspec.yaml | 2 +- geolocator_platform_interface/pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/geolocator/lib/geolocator.dart b/geolocator/lib/geolocator.dart index f1f3849d..f2794616 100644 --- a/geolocator/lib/geolocator.dart +++ b/geolocator/lib/geolocator.dart @@ -4,6 +4,9 @@ import 'package:flutter/foundation.dart'; import 'package:geolocator_apple/geolocator_apple.dart'; import 'package:geolocator_android/geolocator_android.dart'; import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; + +export 'package:geolocator_android/geolocator_android.dart' + show AndroidSettings, ForegroundNotificationConfig, AndroidResource; export 'package:geolocator_apple/geolocator_apple.dart' show AppleSettings, ActivityType; export 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; diff --git a/geolocator/pubspec.yaml b/geolocator/pubspec.yaml index bd91485f..bfbf5e7c 100644 --- a/geolocator/pubspec.yaml +++ b/geolocator/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: sdk: flutter geolocator_platform_interface: ^4.1.0 - geolocator_android: ^4.5.0 + geolocator_android: ^4.3.0 geolocator_apple: ^2.3.0 geolocator_web: ^2.2.0 geolocator_windows: ^0.2.2 diff --git a/geolocator_platform_interface/pubspec.yaml b/geolocator_platform_interface/pubspec.yaml index efb3104c..82489c08 100644 --- a/geolocator_platform_interface/pubspec.yaml +++ b/geolocator_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the geolocator plugin. repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 4.2.0 +version: 4.1.1 dependencies: flutter: From ee037c5439a8b5a3f54c54ed3612a80d406cb03f Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Thu, 2 Nov 2023 12:34:53 +0100 Subject: [PATCH 06/16] Update CHANGELOG.md --- geolocator_platform_interface/CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/geolocator_platform_interface/CHANGELOG.md b/geolocator_platform_interface/CHANGELOG.md index f8a3b8a2..fb4ff66b 100644 --- a/geolocator_platform_interface/CHANGELOG.md +++ b/geolocator_platform_interface/CHANGELOG.md @@ -1,7 +1,3 @@ -## 4.2.0 - -- Includes `satelliteCount` and `satellitesUsedInFix` in `Position`. - ## 4.1.1 - Updates dependencies to latest versions to prevent conflicts with other packages. From 710a3007f781d3f47106da3e8ea626cc0626a7cb Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Thu, 2 Nov 2023 13:07:14 +0100 Subject: [PATCH 07/16] Update pubspec.yaml --- geolocator_android/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geolocator_android/pubspec.yaml b/geolocator_android/pubspec.yaml index 16dea90d..28386b72 100644 --- a/geolocator_android/pubspec.yaml +++ b/geolocator_android/pubspec.yaml @@ -20,7 +20,7 @@ flutter: dependencies: flutter: sdk: flutter - geolocator_platform_interface: ^4.1.1 + geolocator_platform_interface: ^4.1.0 uuid: ^4.1.0 dev_dependencies: From 103ea8b6394bd9e927d020064962563c65860a32 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 14:32:33 +0100 Subject: [PATCH 08/16] Update geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java Co-authored-by: Maurits van Beusekom --- .../java/com/baseflow/geolocator/location/NmeaClient.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java index eb1fe249..427e5c90 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/NmeaClient.java @@ -55,9 +55,11 @@ public NmeaClient(@NonNull Context context, @Nullable LocationOptions locationOp public void onSatelliteStatusChanged(@NonNull GnssStatus status) { gnss_satellite_count = status.getSatelliteCount(); gnss_satellites_used_in_fix = 0; - for (int i = 0; i < gnss_satellite_count; ++i) - if (status.usedInFix(i)) + for (int i = 0; i < gnss_satellite_count; ++i) { + if (status.usedInFix(i)) { ++gnss_satellites_used_in_fix; + } + } } }; } From ed0a5232a64f4fee1825fe2c7f196880765d7a12 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 14:33:50 +0100 Subject: [PATCH 09/16] Update geolocator_android/lib/src/types/android_position.dart Co-authored-by: Maurits van Beusekom --- geolocator_android/lib/src/types/android_position.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/geolocator_android/lib/src/types/android_position.dart b/geolocator_android/lib/src/types/android_position.dart index 562059dc..0cc7efdf 100644 --- a/geolocator_android/lib/src/types/android_position.dart +++ b/geolocator_android/lib/src/types/android_position.dart @@ -62,7 +62,6 @@ class AndroidPosition extends Position { int get hashCode => satelliteCount.hashCode ^ satellitesUsedInFix.hashCode; /// Converts the supplied [Map] to an instance of the [AndroidPosition] class. - static AndroidPosition fromMap(dynamic message) { final Map positionMap = message; From 3848a470f974fee412a5c59234f55e1f01cc778c Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 14:34:01 +0100 Subject: [PATCH 10/16] Update geolocator_android/lib/src/types/android_position.dart Co-authored-by: Maurits van Beusekom --- geolocator_android/lib/src/types/android_position.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geolocator_android/lib/src/types/android_position.dart b/geolocator_android/lib/src/types/android_position.dart index 0cc7efdf..16b6530c 100644 --- a/geolocator_android/lib/src/types/android_position.dart +++ b/geolocator_android/lib/src/types/android_position.dart @@ -8,8 +8,8 @@ class AndroidPosition extends Position { /// Constructs an instance with the given values for testing. [AndroidPosition] /// instances constructed this way won't actually reflect any real information /// from the platform, just whatever was passed in at construction time. - const AndroidPosition( - {required this.satelliteCount, + const AndroidPosition({ + required this.satelliteCount, required this.satellitesUsedInFix, required longitude, required latitude, From 3b08213b6143345ffdef69ce3c4e352806e2567f Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 14:34:16 +0100 Subject: [PATCH 11/16] Update geolocator_android/lib/src/types/android_position.dart Co-authored-by: Maurits van Beusekom --- geolocator_android/lib/src/types/android_position.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/geolocator_android/lib/src/types/android_position.dart b/geolocator_android/lib/src/types/android_position.dart index 16b6530c..827cd0b3 100644 --- a/geolocator_android/lib/src/types/android_position.dart +++ b/geolocator_android/lib/src/types/android_position.dart @@ -22,7 +22,8 @@ class AndroidPosition extends Position { required speed, required speedAccuracy, int? floor, - isMocked = false}) + isMocked = false, + }) : super( longitude: longitude, latitude: latitude, From bd4e86f341bf99f7821dffe618b957d5e23d0829 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 14:47:03 +0100 Subject: [PATCH 12/16] updated formatting --- .../geolocator/location/LocationMapper.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java index 63e1af8a..303e0751 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java @@ -21,28 +21,30 @@ public static Map toHashMap(Location location) { if (location.hasAltitude()) position.put("altitude", location.getAltitude()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasVerticalAccuracy()) - position.put("altitude_accuracy", location.getVerticalAccuracyMeters()); + position.put("altitude_accuracy", location.getVerticalAccuracyMeters()); if (location.hasAccuracy()) position.put("accuracy", (double) location.getAccuracy()); if (location.hasBearing()) position.put("heading", (double) location.getBearing()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasBearingAccuracy()) - position.put("heading_accuracy", location.getBearingAccuracyDegrees()); + position.put("heading_accuracy", location.getBearingAccuracyDegrees()); if (location.hasSpeed()) position.put("speed", (double) location.getSpeed()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasSpeedAccuracy()) position.put("speed_accuracy", (double) location.getSpeedAccuracyMetersPerSecond()); if (location.getExtras() != null) { - if (location.getExtras().containsKey(NmeaClient.NMEA_ALTITUDE_EXTRA)) { - Double mslAltitude = location.getExtras().getDouble(NmeaClient.NMEA_ALTITUDE_EXTRA); - position.put("altitude", mslAltitude); - } - if (location.getExtras().containsKey(NmeaClient.GNSS_SATELLITE_COUNT_EXTRA)) { - Double mslSatelliteCount = location.getExtras().getDouble(NmeaClient.GNSS_SATELLITE_COUNT_EXTRA); - position.put("gnss_satellite_count", mslSatelliteCount); - } - if (location.getExtras().containsKey(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA)) { - Double mslSatellitesUsedInFix = location.getExtras().getDouble(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA); - position.put("gnss_satellites_used_in_fix", mslSatellitesUsedInFix); - } + if (location.getExtras().containsKey(NmeaClient.NMEA_ALTITUDE_EXTRA)) { + Double mslAltitude = location.getExtras().getDouble(NmeaClient.NMEA_ALTITUDE_EXTRA); + position.put("altitude", mslAltitude); + } + if (location.getExtras().containsKey(NmeaClient.GNSS_SATELLITE_COUNT_EXTRA)) { + Double mslSatelliteCount = + location.getExtras().getDouble(NmeaClient.GNSS_SATELLITE_COUNT_EXTRA); + position.put("gnss_satellite_count", mslSatelliteCount); + } + if (location.getExtras().containsKey(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA)) { + Double mslSatellitesUsedInFix = + location.getExtras().getDouble(NmeaClient.GNSS_SATELLITES_USED_IN_FIX_EXTRA); + position.put("gnss_satellites_used_in_fix", mslSatellitesUsedInFix); + } } return position; } From 8fc14da21849e632b63788df440e8c7cdcf0323b Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Thu, 9 Nov 2023 13:37:17 +0100 Subject: [PATCH 13/16] dart format --- .../lib/src/types/android_position.dart | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/geolocator_android/lib/src/types/android_position.dart b/geolocator_android/lib/src/types/android_position.dart index 827cd0b3..4680130a 100644 --- a/geolocator_android/lib/src/types/android_position.dart +++ b/geolocator_android/lib/src/types/android_position.dart @@ -9,22 +9,21 @@ class AndroidPosition extends Position { /// instances constructed this way won't actually reflect any real information /// from the platform, just whatever was passed in at construction time. const AndroidPosition({ - required this.satelliteCount, - required this.satellitesUsedInFix, - required longitude, - required latitude, - required timestamp, - required accuracy, - required altitude, - required altitudeAccuracy, - required heading, - required headingAccuracy, - required speed, - required speedAccuracy, - int? floor, - isMocked = false, - }) - : super( + required this.satelliteCount, + required this.satellitesUsedInFix, + required longitude, + required latitude, + required timestamp, + required accuracy, + required altitude, + required altitudeAccuracy, + required heading, + required headingAccuracy, + required speed, + required speedAccuracy, + int? floor, + isMocked = false, + }) : super( longitude: longitude, latitude: latitude, timestamp: timestamp, From af0bf23264a338eb49592940d7587b59058762ce Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 13 Nov 2023 11:22:29 +0100 Subject: [PATCH 14/16] Update geolocator.dart --- geolocator/lib/geolocator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geolocator/lib/geolocator.dart b/geolocator/lib/geolocator.dart index f2794616..86311aa7 100644 --- a/geolocator/lib/geolocator.dart +++ b/geolocator/lib/geolocator.dart @@ -1,8 +1,8 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:geolocator_apple/geolocator_apple.dart'; import 'package:geolocator_android/geolocator_android.dart'; +import 'package:geolocator_apple/geolocator_apple.dart'; import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; export 'package:geolocator_android/geolocator_android.dart' From 868bf858fb3df2d343cb3c3e5839f57fc6b541d0 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 13 Nov 2023 11:25:21 +0100 Subject: [PATCH 15/16] Update position.dart --- geolocator_platform_interface/lib/src/models/position.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geolocator_platform_interface/lib/src/models/position.dart b/geolocator_platform_interface/lib/src/models/position.dart index 7f727ace..5fdf1566 100644 --- a/geolocator_platform_interface/lib/src/models/position.dart +++ b/geolocator_platform_interface/lib/src/models/position.dart @@ -151,6 +151,7 @@ class Position { longitude: positionMap['longitude'], timestamp: timestamp, altitude: positionMap['altitude'] ?? 0.0, + altitudeAccuracy: positionMap['altitude_accuracy'] ?? 0.0, accuracy: positionMap['accuracy'] ?? 0.0, heading: positionMap['heading'] ?? 0.0, headingAccuracy: positionMap['heading_accuracy'] ?? 0.0, @@ -158,7 +159,6 @@ class Position { speed: positionMap['speed'] ?? 0.0, speedAccuracy: positionMap['speed_accuracy'] ?? 0.0, isMocked: positionMap['is_mocked'] ?? false, - altitudeAccuracy: positionMap['altitude_accuracy'] ?? 0.0, ); } From be3e53fabe2f62db2120084eff97387df5c62ade Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 13 Nov 2023 11:36:06 +0100 Subject: [PATCH 16/16] reverted unused changes --- .../method_channel_geolocator_test.dart | 29 +++++++++---------- .../test/src/models/position_test.dart | 3 +- geolocator_web/lib/src/utils.dart | 29 ++++++++++--------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart b/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart index 1ad99ce9..b313a0ce 100644 --- a/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart +++ b/geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart @@ -10,21 +10,20 @@ import 'event_channel_mock.dart'; import 'method_channel_mock.dart'; Position get mockPosition => Position( - latitude: 52.561270, - longitude: 5.639382, - timestamp: DateTime.fromMillisecondsSinceEpoch( - 500, - isUtc: true, - ), - altitude: 3000.0, - altitudeAccuracy: 2.0, - accuracy: 0.0, - heading: 0.0, - headingAccuracy: 0.0, - speed: 0.0, - speedAccuracy: 0.0, - isMocked: false, - ); + latitude: 52.561270, + longitude: 5.639382, + timestamp: DateTime.fromMillisecondsSinceEpoch( + 500, + isUtc: true, + ), + altitude: 3000.0, + altitudeAccuracy: 2.0, + accuracy: 0.0, + heading: 0.0, + headingAccuracy: 0.0, + speed: 0.0, + speedAccuracy: 0.0, + isMocked: false); void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/geolocator_platform_interface/test/src/models/position_test.dart b/geolocator_platform_interface/test/src/models/position_test.dart index 53252ceb..265429d7 100644 --- a/geolocator_platform_interface/test/src/models/position_test.dart +++ b/geolocator_platform_interface/test/src/models/position_test.dart @@ -1,5 +1,3 @@ -// ignore_for_file: prefer_const_constructors - import 'package:flutter_test/flutter_test.dart'; import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; @@ -532,6 +530,7 @@ void main() { speedAccuracy: 0, isMocked: false, ); + // Act final readablePosition = position.toString(); diff --git a/geolocator_web/lib/src/utils.dart b/geolocator_web/lib/src/utils.dart index ca6c7b36..cd50aee5 100644 --- a/geolocator_web/lib/src/utils.dart +++ b/geolocator_web/lib/src/utils.dart @@ -12,20 +12,21 @@ Position toPosition(html.Geoposition webPosition) { } return Position( - latitude: coords.latitude as double, - longitude: coords.longitude as double, - timestamp: webPosition.timestamp != null - ? DateTime.fromMillisecondsSinceEpoch(webPosition.timestamp!) - : DateTime.now(), - altitude: coords.altitude as double? ?? 0.0, - altitudeAccuracy: coords.altitudeAccuracy as double? ?? 0.0, - accuracy: coords.accuracy as double? ?? 0.0, - heading: coords.heading as double? ?? 0.0, - headingAccuracy: 0.0, - floor: null, - speed: coords.speed as double? ?? 0.0, - speedAccuracy: 0.0, - isMocked: false); + latitude: coords.latitude as double, + longitude: coords.longitude as double, + timestamp: webPosition.timestamp != null + ? DateTime.fromMillisecondsSinceEpoch(webPosition.timestamp!) + : DateTime.now(), + altitude: coords.altitude as double? ?? 0.0, + altitudeAccuracy: coords.altitudeAccuracy as double? ?? 0.0, + accuracy: coords.accuracy as double? ?? 0.0, + heading: coords.heading as double? ?? 0.0, + headingAccuracy: 0.0, + floor: null, + speed: coords.speed as double? ?? 0.0, + speedAccuracy: 0.0, + isMocked: false, + ); } /// Converts the permission result received from the browser into a