Skip to content

Commit

Permalink
Merge pull request #876 from tyler-jewell/master
Browse files Browse the repository at this point in the history
Fixes #875: Add accuracy to LocationData (when available)
  • Loading branch information
bartekpacia authored Aug 11, 2023
2 parents 484e460 + 997f2e2 commit 3bcb77a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/location/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class LocationData {
final double accuracy; // Estimated horizontal accuracy of this location, radial, in meters
final double altitude; // In meters above the WGS 84 reference ellipsoid
final double speed; // In meters/second
final double speedAccuracy; // In meters/second, always 0 on iOS
final double speedAccuracy; // In meters/second, always 0 on iOS and web
final double heading; // Heading is the horizontal direction of travel of this device, in degrees
final double time; // timestamp of the LocationData
final bool isMock; // Is the location currently mocked
Expand Down
15 changes: 9 additions & 6 deletions packages/location_platform_interface/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,33 @@ class LocationData {

/// Estimated horizontal accuracy of this location, radial, in meters
///
/// Always 0 on Web
/// Will be null if not available.
final double? accuracy;

/// Estimated vertical accuracy of this location, in meters.
/// Estimated vertical accuracy of altitude, in meters.
///
/// Will be null if not available.
final double? verticalAccuracy;

/// In meters above the WGS 84 reference ellipsoid. Derived from GPS informations.
///
/// Always 0 on Web
/// Will be null if not available.
final double? altitude;

/// In meters/second
///
/// Always 0 on Web
/// Will be null if not available.
final double? speed;

/// In meters/second
///
/// Always 0 on Web
/// Will be null if not available.
/// Not available on web
final double? speedAccuracy;

/// Heading is the horizontal direction of travel of this device, in degrees
///
/// Always 0 on Web
/// Will be null if not available.
final double? heading;

/// timestamp of the LocationData
Expand Down
27 changes: 20 additions & 7 deletions packages/location_web/lib/location_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class LocationWebPlugin extends LocationPlatform {
}
}

/// Reference: https://developer.chrome.com/blog/permissions-api-for-the-web/
@override
Future<PermissionStatus> requestPermission() async {
try {
Expand All @@ -75,6 +76,11 @@ class LocationWebPlugin extends LocationPlatform {
return true;
}

@override
Future<bool> isBackgroundModeEnabled() async {
return false;
}

@override
Stream<LocationData> get onLocationChanged {
return _geolocation
Expand All @@ -98,15 +104,22 @@ class LocationWebPlugin extends LocationPlatform {
return null;
}

/// Converts a [js.Geoposition] to a [LocationData].
///
/// This method is used to convert the result of the Geolocation API to a
/// [LocationData] object.
///
/// Reference: https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates
///
LocationData _toLocationData(js.Geoposition result) {
return LocationData.fromMap(<String, dynamic>{
'latitude': result.coords!.latitude!.toDouble(),
'longitude': result.coords!.longitude!.toDouble(),
'accuracy': 0,
'altitude': 0,
'speed': 0,
'speed_accuracy': 0,
'heading': 0,
'latitude': result.coords?.latitude?.toDouble(),
'longitude': result.coords?.longitude?.toDouble(),
'altitude': result.coords?.altitude?.toDouble(),
'accuracy': result.coords?.accuracy?.toDouble(),
'verticalAccuracy': result.coords?.altitudeAccuracy?.toDouble(),
'heading': result.coords?.heading?.toDouble(),
'speed': result.coords?.speed?.toDouble(),
'time': result.timestamp!.toDouble(),
});
}
Expand Down

0 comments on commit 3bcb77a

Please sign in to comment.