Skip to content

Commit

Permalink
Fix position property bug (#1415)
Browse files Browse the repository at this point in the history
* Fix position property bug

* Dart format
  • Loading branch information
Wackymax authored Jan 29, 2024
1 parent a578c8a commit 3e170d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
4 changes: 4 additions & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.5.1

* Fixes a bug where the Position class properties were not set correctly.

## 4.5.0

* Creates `AndroidPosition`, a child class of `Position` with Android specific properties.
Expand Down
60 changes: 30 additions & 30 deletions geolocator_android/lib/src/types/android_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ class AndroidPosition extends Position {
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);
longitude: longitude,
latitude: latitude,
timestamp: timestamp,
accuracy: accuracy,
altitude: altitude,
altitudeAccuracy: altitudeAccuracy,
heading: heading,
headingAccuracy: headingAccuracy,
speed: speed,
speedAccuracy: speedAccuracy,
floor: floor,
isMocked: isMocked,
);

/// If available it returns the number of GNSS satellites.
///
Expand All @@ -48,40 +51,37 @@ class AndroidPosition extends Position {
@override
bool operator ==(Object other) {
var areEqual = other is AndroidPosition &&
super == other &&
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;
int get hashCode =>
satelliteCount.hashCode ^ satellitesUsedInFix.hashCode ^ super.hashCode;

/// Converts the supplied [Map] to an instance of the [AndroidPosition] class.
static AndroidPosition fromMap(dynamic message) {
final Map<dynamic, dynamic> positionMap = message;
// Call the Position fromMap method so future changes to the Position class are automatically picked up.
final position = Position.fromMap(positionMap);

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,
latitude: position.latitude,
longitude: position.longitude,
timestamp: position.timestamp,
accuracy: position.accuracy,
altitude: position.altitude,
altitudeAccuracy: position.altitudeAccuracy,
heading: position.heading,
headingAccuracy: position.headingAccuracy,
speed: position.speed,
speedAccuracy: position.speedAccuracy,
floor: position.floor,
isMocked: position.isMocked,
);
}

Expand Down
2 changes: 1 addition & 1 deletion geolocator_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0
version: 4.5.1

environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down

0 comments on commit 3e170d5

Please sign in to comment.