Hey APh, here´s what I´ve found:
if you call getBounds() from withing the initialize function, nothing
is returned (possibly because no map has been initialized?).
Even if you set you <body>´s onlick like this
onClick='initialize(); get_me_bounds();'
where get_me_bounds() is a function that calls getBounds(), undefined
is returned, but one out of a hundred times, it returns bounds!
So I tried this:
onClick='initialize(); setTimeout('get_me_bounds()', 100);'
which delays the call for get_me_bounds() 100 miliseconds, and IT
WORKS!
I think the API is not yet done processing the map construct, so you
have to give it a breath to finish up.
Let me know if this is too crazy.
On Nov 9, 2:05 am, APh <[email protected]> wrote:
> Hi String and ALL!
> My inline call of initialize() is the LAST operator before </body> tag
> and I hope that this is equal to
> string <body onLoad="initialize()">. It was my experiment...
> BUT I'm try both variants! Result is the same -getBounds() don't
> work.
> It was yesterday...
>
> Today I make <body onLoad="initialize()"> version andgetBounds()
> WORK!!!
> Without any special efforts!
> Later 10 min. don't work again. Now work... Paradox!
> It so unstable!
>
> Situation described above is for Chrome. IE8 show message thatgetBounds() is
> not defined as before.
>
> I think that there can be initialize() has a certain magic value. And
> all resources become accessible already after completion of this
> function.
> When I have taken out my business logic (alert("Center...") and alert
> ("Bounds...") ;) for limits of a body of function initialize(), all
> began to work remarkably!
>
> Thx to all!
> R.,
> Alex Philippov
>
> On 8 ноя, 14:43, String <[email protected]> wrote:
>
>
>
> > It's almost definitely a timing issue.
>
> > My first guess is that at the point where you callgetBounds(), the
> > page is not yet fully rendered, so the map doesn't know what its
> > bounds are going to be yet. This is because you're calling your
> > initialize function inline, rather than attaching it to the body's
> > onload event, or otherwise waiting until the page is done loading.
>
> > I'd also suspect that, since v3 doesn't load resources until it needs
> > them,getBounds() may not be able to be called so soon after
> > initializing the map. You may need to move it into an event which
> > fires after the map has finished loading. But that seems less likely;
> > look at my previous suggestion first.
>
> > Good luck with it,
>
> > String
>
> > On Nov 8, 2:15 am, APh <[email protected]> wrote:
>
> > > Hi ALL!
>
> > > I'm try to type bounds of my map via alert() , but can't. <a
> > > href="http://r-komfort.ru/test/v3_bounds.html">[ link ]</a>
>
> > > IE8 message: 'undefined' for code string ".getBounds()".
>
> > > <a href="http://code.google.com/apis/maps/documentation/v3/
> > > reference.html#Map">Documentation</a> say:
> > > "If the map is not yet initialized (i.e. the mapType is still null),
> > > or center and zoom have not been set then the result is null."
>
> > > But I create a map object in this way:
> > > <pre>
> > > var latlngMoscow = new google.maps.LatLng(55.877648, 37.681915);
> > > var myMoscowMapOptions = {
> > > zoom: 15,
> > > center: latlngMoscow,
> > > mapTypeId: google.maps.MapTypeId.ROADMAP
> > > };
>
> > > var mapMoscow = new google.maps.Map(document.getElementById
> > > ("myMoscowMap"), myMoscowMapOptions);
> > > </pre>
>
> > > The string "zoom: 15" is setting zoom or not?
>
> > > What's wrong?
>
> > > Thx in advance!
>
> > > --= APh =--
--
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=.