0

我刚刚将我的代码从 v2 更新到 v3。一切正常,但功能map.fitBounds(); 这是我的示例代码

   var geocoder = new google.maps.Geocoder();

   geocoder.geocode( { 'address': 'your address'}, >function(results, status) { 
       if (status == google.maps.GeocoderStatus.OK) { 

           var newPoint = new google.maps.LatLng(results[0].geometry.location.lat(), >results[0].geometry.location.lng());
           markerBounds.extend(newPoint); 

           var marker = new google.maps.Marker({ 
               map: map,  
               position: results[0].geometry.location 
           }); 
 
       } else { 
           alert('Geocode was not successful for the following reason: ' + status); 
       } 
   }); 

   map.fitBounds(markerBounds);

}

我发现这段代码看起来不错,但 fitBounds() 在这里不起作用。下面的答案中提到了所需的更改。

4

1 回答 1

1

在这种情况下,我们必须编写这样的代码

markerBounds.extend(newPoint);
map.fitBounds(markerBounds); // 这里是函数而不是最后

这对我有用,希望对你也有用。

于 2013-09-21T16:49:48.967 回答