GeoPoint constructor
Creates a point at latitude (from -90 to 90) and longitude (from
-180 to 180), both in degrees.
The constructor is const, so it checks the ranges (and rejects NaN and
the infinities) with asserts only, which a release build skips. A point
out of range is still rejected when it is written: the write fails with
an ArgumentError.
Implementation
// NaN is detected with `x != x`, because `identical(x, double.nan)` never
// matches a computed NaN (and `isNaN` is not usable in constant expressions).
const GeoPoint(this.latitude, this.longitude)
: assert(latitude == latitude, 'Latitude should not be a NaN.'),
assert(
latitude != double.infinity && latitude != double.negativeInfinity,
'Latitude should not be an infinity.',
),
assert(longitude == longitude, 'Longitude should not be a NaN.'),
assert(
longitude != double.infinity && longitude != double.negativeInfinity,
'Longitude should not be an infinity.',
),
assert(
latitude >= -90.0 && latitude <= 90.0,
'Latitude must be in the range of [-90, 90] but was $latitude',
),
assert(
longitude >= -180.0 && longitude <= 180.0,
'Longitude must be in the range of [-180, 180] but was $longitude',
);