Skip to content

Instantly share code, notes, and snippets.

@iampato
Created February 1, 2022 10:39
Show Gist options
  • Select an option

  • Save iampato/cddd25131960fd675297e7cbc1f2f3f5 to your computer and use it in GitHub Desktop.

Select an option

Save iampato/cddd25131960fd675297e7cbc1f2f3f5 to your computer and use it in GitHub Desktop.
class MapsUtils{
static double calculatePolygonArea(List coordinates) {
double area = 0;
if (coordinates.length > 2) {
for (var i = 0; i < coordinates.length - 1; i++) {
var p1 = coordinates[i];
var p2 = coordinates[i + 1];
area += convertToRadian(p2.longitude - p1.longitude) *
(2 +
Math.sin(convertToRadian(p1.latitude)) +
Math.sin(convertToRadian(p2.latitude)));
}
area = area * 6378137 * 6378137 / 2;
}
return area.abs() * 0.000247105; //sq meters to Acres
}
static double convertToRadian(double input) {
return input * Math.pi / 180;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment