【问题标题】:fitBounds function does not show all markersfitBounds 函数不显示所有标记
【发布时间】:2012-04-20 00:56:08
【问题描述】:

我是 Maps API 的新手,我正在尝试在 Sencha Touch 中使用地图。

我在地图上成功绘制了一组标记。但我想缩放地图并将其居中以尽可能紧密地匹配所有标记。

当我调用 fitBounds 函数时,我得到了一个地图视图,其中我的所有标记都位于屏幕的左上角,并且缩放太宽 - 这不是我想要的。

关于如何以最接近的缩放比例在地图视图上获取我的所有标记的任何提示?谢谢!

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);
}

【问题讨论】:

  • 能否提供截图,fitBounds之后会有什么?
  • 我的回答有帮助吗?需要更多帮助吗?
  • 感谢您的回复 - 我尝试了您的建议,但地图仍然将所有标记放在左上角的视线之外。

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


【解决方案1】:

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

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

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 2019-03-22
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 2021-08-18
    • 1970-01-01
    相关资源
    最近更新 更多