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: _toDouble(positionMap['altitude']),
altitudeAccuracy: _toDouble(positionMap['altitude_accuracy']),
accuracy: _toDouble(positionMap['accuracy']),
heading: _toDouble(positionMap['heading']),
headingAccuracy: _toDouble(positionMap['heading_accuracy']),
floor: positionMap['floor'],
speed: _toDouble(positionMap['speed']),
speedAccuracy: _toDouble(positionMap['speed_accuracy']),
isMocked: positionMap['is_mocked'] ?? false,
);
}