I looked at this answer about getting the centroid of a polygon, and basically copied the code.
Because I'm trying to solve the same problem, which is getting the centroid of a polygon, and for the example given (bermuda triangle) it works wonders.
Now, i'm really having this weird bug or I really don't know what's going on but I have a similar code using the polygon i'm trying to get the centroid of.
var bounds = new google.maps.LatLngBounds();
var i;
var polygonCoords = [
new google.maps.LatLng(121.26814396414763 , 14.156734403334724 ),
new google.maps.LatLng(121.2682025135474 , 14.156956159186617 ),
new google.maps.LatLng(121.2673054424065 , 14.15716533202476 ),
new google.maps.LatLng(121.26724861901177 , 14.156951585745787 ),
new google.maps.LatLng(121.26814396414763 ,14.156734403334724 )
];
for (i = 0; i < polygonCoords.length; i++) {
bounds.extend(polygonCoords[i]);
}
console.log(bounds.getCenter());
Shape above is basically a rectangle a very small one. But output in console is :
R {k: 90, B: 14.156949867679714, toString: function, j: function, equals: function…}
The lat is 90 and long is 14.156949867679714, this is plain wrong it doesn't even exist, I don't know what i'm missing really. Thanks!