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`.');
}
final timestamp = positionMap['timestamp'] != null
? DateTime.fromMillisecondsSinceEpoch(positionMap['timestamp'].toInt(),
isUtc: true)
: null;
return Position(
latitude: positionMap['latitude'],
longitude: positionMap['longitude'],
timestamp: timestamp,
altitude: positionMap['altitude'] ?? 0.0,
accuracy: positionMap['accuracy'] ?? 0.0,
heading: positionMap['heading'] ?? 0.0,
floor: positionMap['floor'],
speed: positionMap['speed'] ?? 0.0,
speedAccuracy: positionMap['speed_accuracy'] ?? 0.0,
isMocked: positionMap['is_mocked'] ?? false,
);
}