calculatePolyCoordiantesCentroid method
LatLng?
calculatePolyCoordiantesCentroid(
- List<List<List<LatLng>>> polyCoordinates
)
Implementation
LatLng? calculatePolyCoordiantesCentroid(List<List<List<LatLng>>> polyCoordinates) {
double totalX = 0.0;
double totalY = 0.0;
int totalPoints = 0;
for (List<List<LatLng>> polygon in polyCoordinates) {
for (List<LatLng> ring in polygon) {
for (LatLng point in ring) {
totalX += point.latitude;
totalY += point.longitude;
totalPoints++;
}
}
}
if (totalPoints == 0) {
// Avoid division by zero
return null;
}
double centroidLat = totalX / totalPoints;
double centroidLng = totalY / totalPoints;
return LatLng(centroidLat, centroidLng);
}