fitBounds()不使用地理编码器功能

时间:2013-09-21 08:47:03

标签: google-geocoder fitbounds

我刚刚将代码从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()不起作用。所需的更改在下面的答案中提到。

1 个答案:

答案 0 :(得分:1)

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

  

markerBounds.extend(newPoint);
  map.fitBounds(markerBounds); //这里是功能而不是最终

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

相关问题