Skip to content

Instantly share code, notes, and snippets.

@digitalhydra
Created December 1, 2017 22:52
Show Gist options
  • Save digitalhydra/6577405afb5166e35ce6d3a7eb1ce996 to your computer and use it in GitHub Desktop.
Save digitalhydra/6577405afb5166e35ce6d3a7eb1ce996 to your computer and use it in GitHub Desktop.
get center of polygon in google maps
var bounds = new google.maps.LatLngBounds();
var i;
// The Bermuda Triangle
var polygonCoords = [
new google.maps.LatLng(25.774252, -80.190262),
new google.maps.LatLng(18.466465, -66.118292),
new google.maps.LatLng(32.321384, -64.757370),
new google.maps.LatLng(25.774252, -80.190262)
];
for (i = 0; i < polygonCoords.length; i++) {
bounds.extend(polygonCoords[i]);
}
// The Center of the Bermuda Triangle - (25.3939245, -72.473816)
console.log(bounds.getCenter());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment