2011-08-02 47 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