如何使用 LatLng 数据放大 LatLngBounds 框

How do I enlarge LatLngBounds box using LatLng data

我通过调用获得 google 地图的当前边界:

map.getBounds()

这将 return LatLngBounds。例如:

((-26.574013562724005, -1.5375947819336488), (-25.230016040794602, 3.735842718066351))

如果我想在地图中心周围按百分比(例如 1%)增加地图边界,是否可以获得新的 LatLng 点。

我试过将每个坐标乘以 1.01,但这会移动地图并且不会增加边界。

我想使用增加的框大小来开始缓存标记,以便在用户平移或缩小时保存对服务器的调用。

下图将更好地解释需要发生的事情:

基于 markerclusterer getExtendedBounds 函数你可以使用这个:

function getExtendedBounds(map, overlay) {
    //With _mapBoundsEnlargePixels we add some extra space surrounding the map
    //change this value until you get the desired size
    var _mapBoundsEnlargePixels = 500;

    var projection = overlay.getProjection();
    var bounds = angular.copy(map.getBounds());

    // Turn the bounds into latlng.
    var tr = new google.maps.LatLng(bounds.getNorthEast().lat(),
        bounds.getNorthEast().lng());
    var bl = new google.maps.LatLng(bounds.getSouthWest().lat(),
        bounds.getSouthWest().lng());

    // Convert the points to pixels and extend out
    var trPix = projection.fromLatLngToDivPixel(tr);
    trPix.x = trPix.x + _mapBoundsEnlargePixels;
    trPix.y = trPix.y - _mapBoundsEnlargePixels;

    var blPix = projection.fromLatLngToDivPixel(bl);
    blPix.x = blPix.x - _mapBoundsEnlargePixels;
    blPix.y = blPix.y + _mapBoundsEnlargePixels;

    // Convert the pixel points back to LatLng
    var ne = projection.fromDivPixelToLatLng(trPix);
    var sw = projection.fromDivPixelToLatLng(blPix);

    // Extend the bounds to contain the new bounds.
    bounds.extend(ne);
    bounds.extend(sw);

    return bounds;
}