LatLngBounds.fromPoints constructor
LatLngBounds.fromPoints(
- List<
LatLng> points
Create a new LatLngBounds from a list of LatLng
points. This
calculates the bounding box of the provided points.
Implementation
factory LatLngBounds.fromPoints(List<LatLng> points) {
assert(
points.isNotEmpty,
'LatLngBounds cannot be created with an empty List of LatLng',
);
// initialize bounds with max values.
double minX = maxLongitude;
double maxX = minLongitude;
double minY = maxLatitude;
double maxY = minLatitude;
// find the largest and smallest latitude and longitude
for (final point in points) {
if (point.longitude < minX) minX = point.longitude;
if (point.longitude > maxX) maxX = point.longitude;
if (point.latitude < minY) minY = point.latitude;
if (point.latitude > maxY) maxY = point.latitude;
}
return LatLngBounds.unsafe(
north: maxY,
south: minY,
east: maxX,
west: minX,
);
}