0

I'm stuck trying to calculate a polygon overlay area on a map... I've found a formula but the results does not seems to be right... I've made a test with those locations:

    var locations:[CLLocationCoordinate2D] = []

    locations.append(CLLocationCoordinate2DMake(41.3194, -110.38512))
    locations.append(CLLocationCoordinate2DMake(41.32038, -110.38515))
    locations.append(CLLocationCoordinate2DMake(41.32052, -110.38513))
    locations.append(CLLocationCoordinate2DMake(41.32096, -110.3847))
    locations.append(CLLocationCoordinate2DMake(41.32121, -110.3843))
    locations.append(CLLocationCoordinate2DMake(41.3208, -110.38432))
    locations.append(CLLocationCoordinate2DMake(41.32075, -110.38432))
    locations.append(CLLocationCoordinate2DMake(41.32013, -110.38433))
    locations.append(CLLocationCoordinate2DMake(41.31938, -110.38433))

let polygon:MKPolygon = MKPolygon(coordinates: &locations, count: locations.count) self.mapView.addOverlay(polygon)

FORMULA ***

var area = 0.0;
        for i in 0..<locations.count - 1
        {
            area += atan(
                tan(M_PI / 180 * (locations[i + 1].longitude - locations[i].longitude) / 2) *
                    sin(M_PI / 180 * (locations[i + 1].latitude + locations[i].latitude) / 2) /
                    cos(M_PI / 180 * (locations[i + 1].latitude - locations[i].latitude) / 2))
        }

        if (area < 0)
        {
            area *= -1
        }

        let result =  area * 2 * pow(6378137.0, 2)

        print("AREA OF POLYGON IS \(result)")

The result: 370354609.210868

I dont even know if this number returned by the formula is square feet or what... I need the result in hectare...

Polygon created based on the locations

Thanks a lot, guys...

Cleversou
  • 461
  • 4
  • 16

0 Answers0