title: Calculating the Area of a Polygon When the Polygon's Points are Lat Longs: Which Function is More Accurate?
body: <p>I'm trying to find a way to calculate the area of a polygon using lat long coordinates in a Flex 3 site. Hong007 on Google Maps for Flash group was cool enough to post the following function:</p>
  
  <pre><code>private function GetPolygonArea (polygon : Polygon):Number 
          { 
              var nVer : int = polygon.getOuterVertexCount(); 
              var sz : Number =0; 
              var s : Number =0; 
              var x : Number =0; 
              var y0 : Number =0; 
              var y1 : Number =0; 
              var Maplatlng:LatLng; 
              if (nVer&gt;=3){ 
                 for (var i:int=0; i&lt;nVer; i++){ 
                     Maplatlng = polygon.getOuterVertex(i); 
                     x = Maplatlng.lng(); 
                     if (i&gt;0){ 
                        Maplatlng = polygon.getOuterVertex(i-1); 
                        y0 = Maplatlng.lat(); 
                     } 
                     else{ 
                        Maplatlng = polygon.getOuterVertex(nVer-1); 
                        y0 = Maplatlng.lat(); 
                     }; 
                     if (i&lt;(nVer-1)){ 
                        Maplatlng = polygon.getOuterVertex(i+1); 
                        y1 = Maplatlng.lat(); 
                     } 
                     else{ 
                        Maplatlng = polygon.getOuterVertex(0); 
                        y1 = Maplatlng.lat(); 
                     }; 
                     s = x * (y0-y1); 
                     sz+=s; 
                 }; 
                 //경위도시 1도의 m값을 곱한다(대략 면적 환산) 
                 Maplatlng = polygon.getOuterVertex(0); 
                 var Maplatlng1:LatLng = new 
  com.google.maps.LatLng(Maplatlng.lat()+1, Maplatlng.lng()+1); 
                 var TempDISTANCE:Number = 
  Maplatlng.distanceFrom(Maplatlng1) / Math.sqrt(2); 
                 return Math.abs((sz/2.0) * Math.pow(TempDISTANCE, 2)); 
              }; 
              return 0.0; 
          }
  </code></pre>
  
  <p>I was also playing around with the area calculator at <a href="http://www.freemaptools.com/area-calculator.htm" rel="nofollow noreferrer">http://www.freemaptools.com/area-calculator.htm</a> .</p>
  
  <p>These functions produce slightly different results. I'm trying to figure out which one is more accurate. It seems that hong007's function produces results that are on average slightly larger than freemaptools' function. However, I don't know which one is more accurate. Any advice?</p>