2011-08-02 32 views

回答

88

你在這裏的一半。您只需獲取地圖邊界,然後提取(並正確使用)拐角的座標。

var bounds = map.getBounds(); 
var ne = bounds.getNorthEast(); // LatLng of the north-east corner 
var sw = bounds.getSouthWest(); // LatLng of the south-west corder 

你從上面的兩個西北和東南角落:

var nw = new google.maps.LatLng(ne.lat(), sw.lng()); 
var se = new google.maps.LatLng(sw.lat(), ne.lng()); 

只要記住,地圖必須已經初始化,否則地圖邊界是null或undefined 。

如果您想將檢視約每變化進行更新,使用idle事件偵聽器:

google.maps.event.addListener(map, 'idle', function(ev){ 
    // update the coordinates here 
}); 
+0

感謝您不必使用我的大腦發現NW和SE角落中拯救出來。 – Frug

相關問題