GeoPoint.fromJson constructor

GeoPoint.fromJson(
  1. Map<String, Object?> json
)

Builds a GeoPoint from a JSON map created by toJson.

Throws an ArgumentError if json does not have that shape or the coordinates are out of range.

Implementation

factory GeoPoint.fromJson(Map<String, Object?> json) {
  final Object? latitude = json['latitude'];
  final Object? longitude = json['longitude'];
  if (json['type'] != jsonType || latitude is! num || longitude is! num) {
    throw ArgumentError.value(
      json,
      'json',
      'Not a JSON representation of a GeoPoint',
    );
  }
  if (!(latitude >= -90 && latitude <= 90)) {
    throw RangeError.range(latitude, -90, 90, 'latitude');
  }
  if (!(longitude >= -180 && longitude <= 180)) {
    throw RangeError.range(longitude, -180, 180, 'longitude');
  }
  return GeoPoint(latitude.toDouble(), longitude.toDouble());
}