Skip to content
This repository has been archived by the owner on Jun 20, 2020. It is now read-only.

Add ability to know if location is mocked #2

Merged
merged 4 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import android.location.Location

class LocationData(val latitude: Double,
val longitude: Double,
val altitude: Double
val altitude: Double,
val isMocked: Boolean
) {
companion object {
fun from(location: Location) = LocationData(
latitude = location.latitude,
longitude = location.longitude,
altitude = location.altitude
altitude = location.altitude,
isMocked = location.isFromMockProvider()
)
}
}
5 changes: 5 additions & 0 deletions lib/channel/codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class _Codec {
static double parseJsonNumber(dynamic value) {
return value.runtimeType == int ? (value as int).toDouble() : value;
}

static bool parseJsonBoolean(dynamic value) {
return value.toString() == 'true';
}

static String encodeEnum(dynamic value) {
return value.toString().split('.').last;
Expand Down Expand Up @@ -105,6 +109,7 @@ class _JsonCodec {
_Codec.parseJsonNumber(json['latitude']),
_Codec.parseJsonNumber(json['longitude']),
_Codec.parseJsonNumber(json['altitude']),
_Codec.parseJsonBoolean(json['isMocked']),
);

static Map<String, dynamic> locationUpdatesRequestToJson(
Expand Down
4 changes: 3 additions & 1 deletion lib/data/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
part of new_geolocation;

class Location {
Location._(this.latitude, this.longitude, this.altitude);
Location._(this.latitude, this.longitude, this.altitude, this.isMocked);

/// Latitude in degrees
final double latitude;
Expand All @@ -15,6 +15,8 @@ class Location {
/// Altitude measured in meters.
final double altitude;

final bool isMocked;

@override
String toString() {
return '{lat: $latitude, lng: $longitude}';
Expand Down