Search code examples
geolocationgeocodewikimapia

How to get the area of the polygons from wiki mapia api


I'm Using wiki mapia api to get the geo information. Wiki Mapia

http://api.wikimapia.org/?key=example&function=place.getnearest&lat=12.9605459&lon=77.5649618&count=50&format=json&category=15417.

this api returning, location name lat,lng,min lat lng, max lat lng , polygon. Like that i need polygon area. anyone used this api kindly suggest me how to get the area parameter .


Solution

  • Without using the api, and only using the points returned by the api you may apply the following algorithm (specified here in pseudocode):

    function polygonArea(X, Y, numPoints) 
    { 
        area = 0;         // Accumulates area 
        j = numPoints-1;  // The last vertex is the previous one to first
    
        for (i=0; i<numPoints; i++)
        { 
            area = area +  (X[j]+X[i]) * (Y[j]-Y[i]); 
            j = i;  //j is previous vertex to i
        }
        return area/2;
    }