Skip to content

Instantly share code, notes, and snippets.

@camille-hdl
Created October 21, 2015 07:08
Show Gist options
  • Save camille-hdl/82cb776ce98e81fbc713 to your computer and use it in GitHub Desktop.
Save camille-hdl/82cb776ce98e81fbc713 to your computer and use it in GitHub Desktop.
Google maps API : get polygon bounds
/**
* Recupere les limites d'un polygone
*
* @method getPolygonBounds
* @param {Object} polygon un `polygon` gmap
* @return {Object} bounds
*/
getPolygonBounds: function(polygon) {
var paths = polygon.getPaths();
var bounds = new google.maps.LatLngBounds();
paths.forEach(function(path) {
var ar = path.getArray();
for(var i = 0, l = ar.length;i < l; i++) {
bounds.extend(ar[i]);
}
});
return bounds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment