我对 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/