我在指定位置绘制一个3英里半径的圆,但缩放级别显示整个美国,太平洋和大西洋。如果我通过UI缩放窗口小部件手动放大,则圆圈应该是正确的尺寸。我以为fitBounds()
会自动放大?如果需要明确调用setZoom()
,如何计算正确的缩放级别以包含整个圆圈而不显示圆圈外的太多区域?
function setInitialMapFocusByZipcode(zipcode, desiredRadius)
{
geocoder.geocode(
{ 'address': zipcode }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
usmap.setCenter(results[0].geometry.location);
var circ = new google.maps.Circle({
map: usmap,
fillOpacity: 0.25
});
circ.setRadius(desiredRadius * 1609.344); // desiredRadius=3 in testing
circ.setCenter(results[0].geometry.location);
usmap.fitBounds(circ.getBounds());
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}