Reputation: 6866
I've got this bit of code here:
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);
}
});
}
My problem is that when I call map.setZoom(12) the map just stays at the same zoom level it was already at.
I guess a better solution would be to set it to a zoom level that shows the full selectionArea in the map window.
So I guess this is sort of a double question:
Upvotes: 1
Views: 654
Reputation: 443
I'm not sure I understood your problem. The code you posted geocodes an address and draws a rectangle with the same size of the map bounds. So...
How do I get the zoom level to change when calling setZoom()?
well... it seems ok. Check if your map zoom isn't already set at 12
How would I set the zoom level so that a Rectangle drawn on the map would completely fit in the bounds of the map div?
You can make map fits the bounds with
map.fitBounds(latLngBounds);
Upvotes: 2