Getting Pauline Boundaries in the Google Maps API v3

Are there any simple ways to find the bounding box of a polyline using the Google Maps API v3? I am working on a project where I need to update borders as data is added and removed from the map. This is pretty simple, just using bd.extend (point), where bd is the related object and the point is the LatLng object. The problem is that when I start deleting data, I would like them to change boundaries and zoom in. Are there any built-in functions that can do this or do I need to write something for myself?

+5
source share
3 answers

The v2 API had GPolyline.getBounds()to do just that. However, there seems to be no equivalent method in the v3 API .

You can handle this by overriding changedyour property Polyline MVCObjectto get notified when an object changes state. You can then calculate the bounding box using the method LatLngBounds.extend()you suggested.

I think that Google intentionally skipped such methods from the v3 API while trying to maintain a lightweight API. A similar omission discussed a couple of days ago in the Stack Overflow section was . GMap2.clearOverlays()

+4
source

oenpelli, getBounds(), API V2. .

google.maps.Polyline.prototype.getBounds = function() {
    var bounds = new google.maps.LatLngBounds();
    this.getPath().forEach(function(item, index) {
        bounds.extend(new google.maps.LatLng(item.lat(), item.lng()));
    });
    return bounds;
};

, javascript API, init.

+7

Polyline, getBounds. google maps api v3: , , .

+2
source

All Articles