fromMap method

Position fromMap(
  1. dynamic message
)

Converts the supplied Map to an instance of the Position class.

Implementation

static Position fromMap(dynamic message) {
  if (message == null) {
    throw ArgumentError('The parameter \'message\' should not be null.');
  }

  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 DateTime timestamp = positionMap['timestamp'] != null
      ? DateTime.fromMillisecondsSinceEpoch(positionMap['timestamp'].toInt(),
          isUtc: true)
      : null;

  return Position._(
      latitude: positionMap['latitude'],
      longitude: positionMap['longitude'],
      timestamp: timestamp,
      mocked: positionMap['mocked'] ?? false,
      altitude: positionMap['altitude'] ?? 0.0,
      accuracy: positionMap['accuracy'] ?? 0.0,
      heading: positionMap['heading'] ?? 0.0,
      speed: positionMap['speed'] ?? 0.0,
      speedAccuracy: positionMap['speed_accuracy'] ?? 0.0);
}