title: Polygon area on a map - iOS Swift
body: <p>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: </p>
  
  <pre><code>    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))
  </code></pre>
  
  <p>let polygon:MKPolygon = MKPolygon(coordinates: &amp;locations, count: locations.count)
  self.mapView.addOverlay(polygon)</p>
  
  <p>FORMULA ***</p>
  
  <pre><code>var area = 0.0;
          for i in 0..&lt;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 &lt; 0)
          {
              area *= -1
          }
  
          let result =  area * 2 * pow(6378137.0, 2)
  
          print("AREA OF POLYGON IS \(result)")
  </code></pre>
  
  <p>The result: 370354609.210868</p>
  
  <p>I dont even know if this number returned by the formula is square feet or what... I need the result in hectare...</p>
  
  <p><a href="https://i.stack.imgur.com/fR7SV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fR7SV.jpg" alt="Polygon created based on the locations"></a></p>
  
  <p>Thanks a lot, guys...</p>