Location.fromJson constructor

Location.fromJson(
  1. Map<String, dynamic> json
)

Creates a Location from a decoded json entry.

Could throw a JsonMissingKeyException if latitude or longitude could not be found in the json. Throws a TypeError if the values couldn't be parsed as double.

Implementation

factory Location.fromJson(Map<String, dynamic> json) {
  final double latitude = json.containsKey(DirectoryKeys.latitude)
      ? json[DirectoryKeys.latitude] as double
      : throw JsonMissingKeyException(
          DirectoryKeys.latitude, json.toString());
  final double longitude = json.containsKey(DirectoryKeys.longitude)
      ? json[DirectoryKeys.longitude] as double
      : throw JsonMissingKeyException(
          DirectoryKeys.longitude, json.toString());
  return Location(latitude, longitude);
}