calculateArea static method
根据提供的多边形顶点坐标points
计算多边形的面积
Implementation
static double calculateArea(List<LatLng> points) {
int triangleCount = 3;
if (points.length < triangleCount) {
return 0.0;
}
double s = 0;
double metrePerDegree = EARTHRADIUS * DEG_TO_RAD;
int count = points.length;
for (int i = 0; i < count; ++i) {
LatLng coordPrev = points[i];
LatLng coordNext = points[((i + 1) % count)];
double x1 = coordPrev.longitude *
metrePerDegree *
cos(coordPrev.latitude * DEG_TO_RAD);
double y1 = coordPrev.latitude * metrePerDegree;
double x2 = coordNext.longitude *
metrePerDegree *
cos(coordNext.latitude * DEG_TO_RAD);
double y2 = coordNext.latitude * metrePerDegree;
s += x1 * y2 - x2 * y1;
}
return (s / 2.0).abs();
}