Created
February 1, 2022 10:39
-
-
Save iampato/cddd25131960fd675297e7cbc1f2f3f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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