setZoom after fitBounds

2,357 views
Skip to first unread message

Andy Frank

unread,
Oct 2, 2009, 6:33:15 PM10/2/09
to Google Maps JavaScript API v3
Hello!

I have poured over the docs, issues, and this group, but can't seem to
find an answer for this question:

I have a widget that displays a set of configurable lat/long values.
Calling fitBounds() works well for most cases to find the right zoom
level and bounds. However, sometimes the zoom level is not
appropriate, so I would like to override with an explicit zoom level
after the contents have been centered in the frame. This most often
comes up when using a single lat/long value. But attempting to set
the zoom level after calling fitBounds() seems to have no effect:

map.fitBounds(bounds);
map.setZoom(14); // <-- HAS NO EFFECT!

I've tried to simply the code in an example here:
http://www.andyfrank.com/test/test.html

This seems like a bug, so I can post a bug report, but figured I would
get some feedback here first. Thanks for any help!

- Andy

Esa

unread,
Oct 3, 2009, 10:21:07 AM10/3/09
to Google Maps JavaScript API v3
I get 'too much recursion' with FF. I think it is the zero size of the
bounds:

return new google.maps.LatLngBounds(
new google.maps.LatLng(37.536755, -77.433238),
new google.maps.LatLng(37.536755, -77.433238));

Andy Frank

unread,
Oct 5, 2009, 8:30:11 AM10/5/09
to Google Maps JavaScript API v3
Indeed. Works as described above in Chrome. In both cases sounds
like a bug here?

Marc

unread,
Oct 5, 2009, 6:25:02 PM10/5/09
to Google Maps JavaScript API v3
In this case, why not use:

map.setCenter(bounds.getCenter());
map.setZoom(14);

Andy Frank

unread,
Oct 6, 2009, 8:06:48 AM10/6/09
to Google Maps JavaScript API v3
Marc - I considered that - and now that I think about it again, that
would handle my single lat/lng case, since I could initialize the zoom
there to some reasonable value. However, I still need to handle the
other case where I use fitBounds to center/zoom a set of coords - and
then fine tune with setZoom.
Reply all
Reply to author
Forward
0 new messages