getCentroidOfPolygon

Calculates the centroid of a polygon.

This function works for both convex and non-convex (concave) simple polygons. It assumes the polygon is not self-intersecting.

  • @param polygon The polygon for which to calculate the centroid. It is assumed the first and last points of the polygon's outer ring are the same (closed).

Return

The centroid coordinate as a LngLatAlt object, or null if the polygon is invalid.