Search code examples
iosgoogle-mapscllocationgmsmapview

Find Inner most Polygon using actual Area from array of nested Polygon


I have Array of GMSPath and have Coordinate. I want to find out Path in which this Coordinate falls. I am able to find out total polygons in which this location falls. (Using this https://stackoverflow.com/a/38826411/2225439) Everything is working fine up to this step.

The Actual issue comes when One closed GMSPath overlap with another Closed GMSPath and Coordinate is in overlapped area. As per my requirement, I have to get only one GMSPath out of these two and which have the smaller area than another.

Please refer Image for better understanding.

enter image description here


Solution

  • You can find out the area of GMSPolygon by using following method from Google Maps iOS SDK, GMSGeometryArea(), it provides area of given polygon. Now you have area, so you can compare different polygons and find innermost area.

    double GMSGeometryArea(GMSPath *path);
    

    As per description provided by google

    Returns the area of a geodesic polygon defined by |path| on Earth.
    The "inside" of the polygon is defined as not containing the South pole.
    If |path| is not closed, it is implicitly treated as a closed path nevertheless and the result is the same.
    All coordinates of the path must be valid.
    If any segment of the path is a pair of antipodal points, the result is undefined -- because two antipodal points do not form a unique great circle segment on the sphere.
    The polygon must be simple (not self-overlapping) and may be concave.