谷歌地图fitBounds填充?

这个问题在这里已经有了答案:

  • Google Maps API 3 fitBounds填充 - 确保标记不会被叠加控件遮盖6个答案

  • 一段时间后,我发现了一个可行的解决方案。

    if (this.map.getProjection()) {
        var offsetx = 200;
        var offsety = 0;
    
        var point1 = this.map.getProjection().fromLatLngToPoint(bounds.getSouthWest());
        this.map.fitBounds(bounds);
    
        var point2 = new google.maps.Point(
            ( (typeof(offsetx) == 'number' ? offsetx : 0) / Math.pow(2, this.map.getZoom()) ) || 0,
            ( (typeof(offsety) == 'number' ? offsety : 0) / Math.pow(2, this.map.getZoom()) ) || 0
        );          
    
        var newPoint = this.map.getProjection().fromPointToLatLng(new google.maps.Point(
            point1.x - point2.x,
            point1.y + point2.y
        ));
    
        bounds.extend(newPoint);
        this.map.fitBounds(bounds);
    }
    

    的jsfiddle

    链接地址: http://www.djcxy.com/p/81541.html

    上一篇: Google maps fitBounds with padding?

    下一篇: Google maps API V3 fitBounds() not working