Skip to content

Commit

Permalink
Add altitude accuracy and heading accuracy to Position [Platform Inte…
Browse files Browse the repository at this point in the history
…rface] (#1330)

* Add `altitudeAccuracy` and `headingAccuracy` to `Position` model

* Update CHANGELOG and version
  • Loading branch information
JeroenWeener authored Sep 22, 2023
1 parent 035227d commit baa199a
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 34 deletions.
4 changes: 4 additions & 0 deletions geolocator_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.1.0

- Includes `altitudeAccuracy` and `headingAccuracy` in `Position`.

## 4.0.8

- Updates documentation for `getCurrentPosition()` and `LocationAccuracy`, to clarify the behavior of location accuracy on Android devices.
Expand Down
22 changes: 22 additions & 0 deletions geolocator_platform_interface/lib/src/models/position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Position {
required this.timestamp,
required this.accuracy,
required this.altitude,
required this.altitudeAccuracy,
required this.heading,
required this.headingAccuracy,
required this.speed,
required this.speedAccuracy,
this.floor,
Expand All @@ -36,6 +38,12 @@ class Position {
/// value is 0.0.
final double altitude;

/// The estimated vertical accuracy of the position in meters.
///
/// The accuracy is not available on all devices. In these cases the value is
/// 0.0.
final double altitudeAccuracy;

/// The estimated horizontal accuracy of the position in meters.
///
/// The accuracy is not available on all devices. In these cases the value is
Expand All @@ -48,6 +56,12 @@ class Position {
/// 0.0.
final double heading;

/// The estimated heading accuracy of the position in degrees.
///
/// The heading accuracy is not available on all devices. In these cases the
/// value is 0.0.
final double headingAccuracy;

/// The floor specifies the floor of the building on which the device is
/// located.
///
Expand Down Expand Up @@ -79,7 +93,9 @@ class Position {
var areEqual = other is Position &&
other.accuracy == accuracy &&
other.altitude == altitude &&
other.altitudeAccuracy == altitudeAccuracy &&
other.heading == heading &&
other.headingAccuracy == headingAccuracy &&
other.latitude == latitude &&
other.longitude == longitude &&
other.floor == floor &&
Expand All @@ -95,7 +111,9 @@ class Position {
int get hashCode =>
accuracy.hashCode ^
altitude.hashCode ^
altitudeAccuracy.hashCode ^
heading.hashCode ^
headingAccuracy.hashCode ^
latitude.hashCode ^
longitude.hashCode ^
floor.hashCode ^
Expand Down Expand Up @@ -133,8 +151,10 @@ 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,
floor: positionMap['floor'],
speed: positionMap['speed'] ?? 0.0,
speedAccuracy: positionMap['speed_accuracy'] ?? 0.0,
Expand All @@ -150,8 +170,10 @@ class Position {
'timestamp': timestamp?.millisecondsSinceEpoch,
'accuracy': accuracy,
'altitude': altitude,
'altitude_accuracy': altitudeAccuracy,
'floor': floor,
'heading': heading,
'heading_accuracy': headingAccuracy,
'speed': speed,
'speed_accuracy': speedAccuracy,
'is_mocked': isMocked,
Expand Down
2 changes: 1 addition & 1 deletion geolocator_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.8
version: 4.1.0

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Position get mockPosition => Position(
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);
Expand All @@ -33,7 +35,6 @@ void main() {

group('checkPermission: When checking for permission', () {
test(
// ignore: lines_longer_than_80_chars
'Should receive whenInUse if permission is granted when App is in use',
() async {
// Arrange
Expand Down Expand Up @@ -234,7 +235,7 @@ void main() {
expect(locationAccuracy, LocationAccuracyStatus.reduced);
});

test('Should receive reduced accuracy if Location Accuracy is reduced',
test('Should receive reduced accuracy if Location Accuracy is precise',
() async {
// Arrange
MethodChannelMock(
Expand All @@ -254,7 +255,6 @@ void main() {

group('requestPermission: When requesting for permission', () {
test(
// ignore: lines_longer_than_80_chars
'Should receive whenInUse if permission is granted when App is in use',
() async {
// Arrange
Expand Down Expand Up @@ -608,7 +608,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Should throw a location service disabled exception if location services are disabled',
() async {
// Arrange
Expand Down Expand Up @@ -727,9 +726,7 @@ void main() {
streamSubscription = null;
});

test(
// ignore: lines_longer_than_80_chars
'Should correctly handle done event', () async {
test('Should correctly handle done event', () async {
// Arrange
final completer = Completer();
completer.future.timeout(const Duration(milliseconds: 50),
Expand All @@ -755,7 +752,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a stream with position updates if permissions are granted',
() async {
// Arrange
Expand Down Expand Up @@ -785,9 +781,7 @@ void main() {
await streamController.close();
});

test(
// ignore: lines_longer_than_80_chars
'Should continue listening to the stream when exception is thrown ',
test('Should continue listening to the stream when exception is thrown ',
() async {
// Arrange
final streamController =
Expand Down Expand Up @@ -828,7 +822,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a permission denied exception if permission is denied',
() async {
// Arrange
Expand Down Expand Up @@ -866,7 +859,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a location service disabled exception if location service is disabled',
() async {
// Arrange
Expand Down Expand Up @@ -899,9 +891,8 @@ void main() {
streamController.close();
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a already subscribed exception', () async {
test('Should receive a permission request in progress exception',
() async {
// Arrange
final streamController =
StreamController<PlatformException>.broadcast();
Expand Down Expand Up @@ -932,9 +923,7 @@ void main() {
streamController.close();
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a already subscribed exception', () async {
test('Should receive an already subscribed exception', () async {
// Arrange
final streamController =
StreamController<PlatformException>.broadcast();
Expand Down Expand Up @@ -965,9 +954,7 @@ void main() {
streamController.close();
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a position update exception', () async {
test('Should receive a position update exception', () async {
// Arrange
final streamController =
StreamController<PlatformException>.broadcast();
Expand Down Expand Up @@ -1077,7 +1064,6 @@ void main() {
});

group(
// ignore: lines_longer_than_80_chars
'getServiceStream: When requesting a stream of location service status updates',
() {
group('And requesting for location service status updates multiple times',
Expand All @@ -1095,7 +1081,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Should receive a stream with location service updates if permissions are granted',
() async {
// Arrange
Expand All @@ -1122,9 +1107,7 @@ void main() {
await streamController.close();
});

test(
// ignore: lines_longer_than_80_chars
'Should receive an exception if android activity is missing',
test('Should receive an exception if android activity is missing',
() async {
// Arrange
final streamController =
Expand Down
Loading

0 comments on commit baa199a

Please sign in to comment.