通过android gps采集的坐标为球面坐标,如果此种坐标形成的ploygon直接进行面积的计算是不可行的,计算出来的面积为负数。于是需要将球面坐标转换成平面坐标在进行计算方可。
public static double getArea(Listlist, MapView mapView) { DecimalFormat dfAreaR = new DecimalFormat("0.00"); Polygon polygon = new Polygon(); for (int i = 0; i < list.size(); i++) { Point pt = list.get(i); if (i == 0) { polygon.startPath(pt); } else { polygon.lineTo(pt); } } polygon.closeAllPaths(); SpatialReference webMercator = SpatialReference.create(2362); //project from wgs84 Polygon newPoly = (Polygon) GeometryEngine.project(polygon, mapView.getSpatialReference(),webMercator); double area = newPoly.calculateArea2D(); return Double.valueOf(dfAreaR.format(area)); }