I had the same problem. My solution is (it works):

google.maps.event.addListener(map, 'zoom_changed', function() {//ascoltatore
sull'evento zoom della mappa
zoomChangeBoundsListener =
google.maps.event.addListener(map,'bounds_changed',function (event) {
      //here I have the correct zoom level
google.maps.event.removeListener(zoomChangeBoundsListener);
});
});

On Wed, Jan 13, 2010 at 5:12 AM, fly2279 <[email protected]> wrote:

> Well it did work but not consistently. If I alert() the value of
> this.getZoom() in the zoom_changed listener it gives me the correct
> value. I save the value in a variable and  when I take it out the alert
> () it doesn't give the correct value. It's like it needs to wait 1
> millisecond to actually load the correct value after fitbounds is
> called. Any suggestions?
>
> On Jan 12, 1:16 pm, Chad Killingsworth
> <[email protected]> wrote:
> > You have to reset the flag value inside the zoom_changed event
> > listener - not in your original function. Here's a rough example of
> > how I would do it:
> >
> > var FindCorrectZoom = false;
> > function AddMarkers() {
> >   for(var i = 0; i < 10; i++ {
> >      AddMarker(i);
> >   }
> >   FindCorrectZoom = true;
> >   map.fitBounds(MarkerBounds);
> >
> > }
> >
> > function processFitBoundsZoomChanged(currentZoom) {
> >   //do something here
> >
> > }
> >
> > function zoom_changed_listener() {
> >    if(FindCorrectZoom) {
> >      FindCorrectZoom = false;
> >      processFitBoundsZoomChanged(this.getZoom());
> >    }}
> >
> > google.maps.event.addListener(map, 'zoom_changed',
> > zoom_changed_listener);
> >
> > I used this technique in my code to limit the maximum zoom level a
> > call to fitBounds could use.
> >
> > Chad Killingsworth
> >
> > On Jan 12, 9:00 am, fly2279 <[email protected]> wrote:
> >
> >
> >
> > > I've tried setting a flag variable before the loop that adds markers
> > > and then resetting the variable to false afterwards. It's like the
> > > zoom_level doesn't actually get changed until a short time after all
> > > the markers are placed. I can use setTimout to 100 and then get the
> > > proper zoom_level returned after placing the markers but I have a
> > > feeling that amount of time will change with a change in number of
> > > markers being placed. Can someone shed some light on what I'm doing
> > > wrong?
> >
> > > On Jan 12, 6:54 am, Chad Killingsworth
> >
> > > <[email protected]> wrote:
> > > > I encountered this problem as well. As far as I can tell, you have to
> > > > get the proper zoom value inside your zoom_changed event listener.
> >
> > > > I got around that by setting a flag value then adding my markers and
> > > > calling fitBounds. Inside my zoom_changed listener, if the flag value
> > > > was set, I reset it then called another function to continue
> > > > processing.
> >
> > > > Hope that helps,
> >
> > > > Chad Killingsworth
> >
> > > > On Jan 11, 9:52 pm, fly2279 <[email protected]> wrote:
> >
> > > > > I am placing markers on the map in a loop and extending the bounds
> of
> > > > > the map to fit the markers. When I use getZoom() to get the zoom
> level
> > > > > after fitting the bounds it's the same as the initial value for the
> > > > > map. My initial zoom value is set to 8 and that's what's returned
> > > > > after fitting the bounds. I placed a listener on zoom_changed and
> > > > > getZoom() returns 10 after fitting the bounds. How do I get the
> zoom
> > > > > level after fitting the bounds since calling getZoom() immediately
> > > > > after doesn't seem to return the correct value?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-js-api-v3%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>
>
>
--
You received this message because you are subscribed to the Google Groups "Google Maps _javascript_ API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to