Polyline bounds?

2,398 views
Skip to first unread message

Nik

unread,
Sep 29, 2009, 2:27:53 PM9/29/09
to Google Maps JavaScript API v3
Dear Maps v3 group,

one of the nice v2 features was that I could call getBounds on a
polyline, and then zoom/center on those bounds.

I do see a map.fitBounds call, but no polyline.getBounds...! Is there
any way to achieve the same effect?

thanks,
kind regards,
Nik.

Ben Appleton

unread,
Sep 29, 2009, 6:38:23 PM9/29/09
to google-map...@googlegroups.com
Here is a function that works for Polylines or Polygons:

function getBoundsForPoly(poly) {
  var bounds = new google.maps.LatLngBounds;
  poly.getPath().forEach(function(latLng) {
    bounds.extend(latLng);
  });
  return bounds;

Nik

unread,
Sep 30, 2009, 2:42:09 AM9/30/09
to Google Maps JavaScript API v3
Didn't think of that, thanks!!
Reply all
Reply to author
Forward
0 new messages