1

我收到错误“对象(NaN,NaN)没有方法'extend'”,当我尝试扩展谷歌地图上的每个标记的边界。获取错误“对象(NaN,NaN)没有方法'扩展'”当扩展Google Map v3的边界时

下面是一些代码:

首先我全局声明的范围:

var bounds = new google.maps.LatLngBounds(); 

然后我使用以下代码

function displayMarker(appID, title, image, imageType, address, markerType, lat, lng, markersCount) { 
    var listingLatLng = new google.maps.LatLng(lat, lng); 
    var marker = new google.maps.Marker({ 
     position: listingLatLng, 
     map: map, 
     icon: markerType ? imgBluePin : imgGreenPin, 
     title: title + address 
    }); 

    bounds.extend(listingLatLng); 
    map.fitBounds(bounds); 

    var infowindow = new google.maps.InfoWindow(
     { content: GetContent(title, image, imageType, address), 
      size: new google.maps.Size(50, 50) 
     }); 

    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.open(map, marker); 
    }); 

它们设置的每个markeer,当我加载的页面当代码试图扩展边界时,我得到上面提到的错误,例如on line

bounds.extend(listingLatLng); 

为什么我得到那个错误?

谢谢。

+0

看起来不错!在控制台中尝试'for(var j in bounds){console.log(j)}',并调查'bounds'对象没有该方法的原因。 – jenswirf 2012-01-17 13:25:55

+0

这可能是一个单个标记hasn' t获得lat和lng的值吗? – duncan 2012-01-17 14:42:31

+0

所有的标记都得到正确的坐标 – Thea 2012-01-17 14:43:24

回答

0

我找到了错误的原因。除声明范围为

var bounds = new google.maps.LatLngBounds(); 

它被宣布为

var bounds = new google.maps.LatLng(); 

这是错误的。