fromMap static method
Converts the supplied Map to an instance of the Position class.
Implementation
static Position fromMap(dynamic message) {
final Map<dynamic, dynamic> positionMap = message;
if (!positionMap.containsKey('latitude')) {
throw ArgumentError.value(positionMap, 'positionMap',
'The supplied map doesn\'t contain the mandatory key `latitude`.');
}
if (!positionMap.containsKey('longitude')) {
throw ArgumentError.value(positionMap, 'positionMap',
'The supplied map doesn\'t contain the mandatory key `longitude`.');
}
// Assume that the timestamp is null if the map does not contain one
dynamic timestampInMap = positionMap['timestamp'];
final timestamp = timestampInMap == null
? DateTime.now()
: DateTime.fromMillisecondsSinceEpoch(
timestampInMap.toInt(),
isUtc: true,
);
return Position(
latitude: positionMap['latitude'],
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,
isMocked: positionMap['is_mocked'] ?? false,
);
}