2

This question is on the similar lines of the below question. But i am asking this question since that question does not answer the requirements .

Area of an irregular polygon using side lengths in ios

overview of the app

1 - User moves on his vehicle with his iPhone/iPad and we are supposed to plot his co-ordinates.

2 - After he finishes his ride, we are suppose to draw a polygon covering all his co-ordinates

3 - Calculate the area covered by the polygon.

i have referred maps API and could not find any methods that calculates the area.

Is there any 3rd party library / a mechanism which will help me in calculating the area of the polygon in iOS maps..

Community
  • 1
  • 1
A for Alpha
  • 2,904
  • 8
  • 42
  • 76
  • This link may help someone http://stackoverflow.com/a/36090029/3918500 – dev_binod Mar 22 '16 at 06:42
  • If anyone else still need this, this worked for me --> http://stackoverflow.com/questions/29513966/calculate-area-of-mkpolygon-in-an-mkmapview – Cleversou Mar 06 '17 at 04:47

2 Answers2

1

From the Google Maps v3 API documentation, the geometry functions are part of a library that is not loaded by default:

The concepts within this document refer to features only available within the google.maps.geometry library. This library is not loaded by default when you load the Maps Javascript API but must be explicitly specified through use of a libraries bootstrap parameter.

In order to load and use the geometry funcitons within your page, you need to inform Google that you will be using the geometry library, by adding it to your initial Google API call by including libraries=geometry:

This will then load the geometry library and your z variable will contain an object.

Test page with working code:

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
      html, body, #map_canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>
<script type="text/javascript">
    var map;
    function initialize()
    {
        var myOptions = {
          zoom: 8,
          center: new google.maps.LatLng(-34.397, 150.644),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
<script>
function test()
{
var arr = new Array()
arr.push('51.5001524,-0.1262362');
arr.push('52.5001524,-1.1262362');
arr.push('53.5001524,-2.1262362');
arr.push('54.5001524,-3.1262362');
dibuV(arr);
}
function dibuV(area)
{
var a = new Array();

for(var i=0; i<area.length; i++)
{
    var uno = area[i].split(",");
    a[i] = new google.maps.LatLng(uno[0],uno[1]);
}

poligon = new google.maps.Polygon({
    paths: a,
    strokeColor: "#22B14C",
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: "#22B14C",   
    fillOpacity: 0.35   
})  

poligon.setMap(map);//until here is ok 
var z = google.maps.geometry.spherical.computeArea(myPolyline.getPath().getArray());
alert(z);
}
</script>
</head>
<body onload="test();">
    <div id="map_canvas"></div>
</body>
</html>
Vizllx
  • 9,135
  • 1
  • 41
  • 79
0

This may help to implement your own solution: Area of a polygon (Coordinate Geometry)

imihaly
  • 1,838
  • 13
  • 11