Skip to content

Instantly share code, notes, and snippets.

@Ankit-Slnk
Created March 15, 2023 11:40
Show Gist options
  • Save Ankit-Slnk/25ce2c9d87d8d3b53f16903252fe7d25 to your computer and use it in GitHub Desktop.
Save Ankit-Slnk/25ce2c9d87d8d3b53f16903252fe7d25 to your computer and use it in GitHub Desktop.
Coordinates list to bound
static LatLngBounds getBounds(List<LatLng> polylineCoordinates) {
double x0, x1, y0, y1;
for (LatLng latLng in polylineCoordinates) {
if (latLng.latitude != null && latLng.longitude != null) {
if (x0 == null) {
x0 = x1 = latLng.latitude;
y0 = y1 = latLng.longitude;
} else {
if (latLng.latitude > x1) x1 = latLng.latitude;
if (latLng.latitude < x0) x0 = latLng.latitude;
if (latLng.longitude > y1) y1 = latLng.longitude;
if (latLng.longitude < y0) y0 = latLng.longitude;
}
}
}
return LatLngBounds(northeast: LatLng(x1, y1), southwest: LatLng(x0, y0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment