2012-04-20 34 views
2

我對Maps API相當陌生,我試圖在Sencha Touch中使用地圖。fitBounds函數不顯示所有標記

我在地圖上成功繪製了一組標記。但我想縮放並居中地圖以儘可能緊密地貼合所有標記。

當我調用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); 
} 
+0

你能提供一個截圖,你會在'fitBounds'後面看到什麼? – Engineer 2012-04-20 20:49:39

+0

我的回答有幫助嗎?需要更多的幫助? – msonsona 2012-04-24 00:23:58

+0

感謝您的回覆 - 我嘗試了您的建議,但地圖仍將所有標記放在左上角的視線之外。 – 2012-04-24 15:47:45

回答

2

我用(後for循環)什麼:

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

希望它能幫助!