【发布时间】:2011-07-11 08:43:16
【问题描述】:
我这里有这段代码:
function ShowSelection(addr){
var latLngBounds;
geocoder.geocode({ "address": addr }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (selectionArea === undefined || selectionArea === null) {
selectionArea = new google.maps.Rectangle({
map: map
});
}
latLngBounds = results[0].geometry.bounds;
selectionArea.setBounds(latLngBounds);
map.panTo(latLngBounds.getCenter());
map.setZoom(12);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
我的问题是,当我调用 map.setZoom(12) 时,地图只是保持在原来的缩放级别。
我想更好的解决方案是将其设置为在地图窗口中显示完整 selectionArea 的缩放级别。
所以我想这是一个双重问题:
- 如何在调用 setZoom() 时更改缩放级别?
- 如何设置缩放级别,以便在地图上绘制的 Rectangle 完全适合地图 div 的边界? (我正在寻找的预期效果是让地图平移到 selectionArea 的中心点,并且地图的边界大于选择区域的边界,即整个 selectionArea 在地图上不可见滚动。
【问题讨论】:
标签: google-maps google-maps-api-3