Created
June 19, 2021 10:50
-
-
Save Ankit-Slnk/6f52e495913b4caba1445d45de5982d1 to your computer and use it in GitHub Desktop.
get LatLng Bounds of multiple coordinates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static LatLngBounds getBounds(List<LatLng> polylineCoordinates) { | |
double x0, x1, y0, y1; | |
for (LatLng latLng in polylineCoordinates) { | |
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