google-maps - fitBounds 函数不显示所有标记

标签 google-maps google-maps-api-3

我对 Maps API 还很陌生,我正在尝试在 Sencha Touch 中使用 map 。

我在 map 上成功绘制了一系列标记。但我想缩放 map 并将其居中,以尽可能紧密地适应所有标记。

当我调用 fitBounds 函数时,我会看到 map View ,其中所有标记都位于屏幕的左上角,并且缩放太宽 - 这不是我想要的。

有关如何以最接近的缩放比例在 map View 上获取所有标记的任何提示?谢谢!

function setCenter()
{
    var bounds = new google.maps.LatLngBounds();

    for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
        //  And increase the bounds to take this point
        bounds.extend (LatLngList[i]);
    }

    map.getMap().fitBounds(bounds);
}

最佳答案

我使用的(for循环之后):

map_center = bounds.getCenter();
map.setCenter(map_center);
map.panToBounds(bounds);
map.fitBounds(bounds);

希望对你有帮助!

关于google-maps - fitBounds 函数不显示所有标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10238878/

相关文章:

javascript - 声明一个全局谷歌地图对象

java - 如何限制 Google Maps API AutocompleteService 提供越界建议

javascript - 如何正确使用 computeDistanceBetween()?

google-maps-api-3 - Google Maps API data.remove 不起作用

javascript - 谷歌地图javascript api标记弹出窗口仅显示在中心

javascript - 自定义非 Google map 上的地理位置

google-maps - 谷歌地图 : Retrieve nearby subway station's latitude and longitude?

ios - 基于指南针旋转 GMSMapView

google-maps-api-3 - 尝试添加右键删除标记功能,以工作左键添加标记代码

javascript - 谷歌地图 v3 标记不显示 ie 8 和 9