0

I am using the below code to find the center of the polygon to print some text on the polygon but it doesn't work for polygon that showed in the picture(image link at the end)

private LatLng getPolygonCenterPoint(ArrayList<LatLng> polygonPointsList){
    LatLng centerLatLng = null;
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for(int i = 0 ; i < polygonPointsList.size() ; i++)
    {
        builder.include(polygonPointsList.get(i));
    }
    LatLngBounds bounds = builder.build();
    centerLatLng =  bounds.getCenter();

    return centerLatLng;
}

HOW TO FIND THE CENTER LATLNG OF POLYGON(as below picture) AND THE LATLNG SHOULD BE INSIDE THE POLYGON. ***click on here to see the polygon***

  • Possible duplicate of [How to get the center of a polygon in google maps v3?](https://stackoverflow.com/questions/3081021/how-to-get-the-center-of-a-polygon-in-google-maps-v3) – Zaid Mirza Dec 19 '18 at 09:54
  • Not a duplicate, but since your polygon is concave, you can have a look at this : https://stackoverflow.com/a/9939071/783707 – Ankur Aggarwal Dec 19 '18 at 10:46
  • The `LatLngBounds.getCenter` is well defined as the average of the points ; your first task is to properly define what you mean as center which would consistenly get what you want. (Maybe put a dot on your picture to help explain.) –  Dec 24 '18 at 01:11

1 Answers1

2

No, the center shouldn't be in the your polygon. The center is the center of the bounds that contains all the points.
This center is useful for centering the view.

What exactly do you mean by the center in the polygon? How do you define it?

Kevin Robatel
  • 8,025
  • 3
  • 44
  • 57