[Google Maps API v2] Re: getting rid of function initialize()
I think your problems are about grasping the sequence of events.
If you load the script with a "standard" script tag, the API is loaded
immediately.
You can then have in-line code, i.e. code that executes as the browser
loads the page, that uses things defined in the API like GIcons.
If you load the script in "jsapi" fashion, the API script load is
delayed.
If you were to have code running inline that calls for e.g. GIcons, it
will fail - that code is trying to run before the API has loaded and
defined what a GIcon is.
So you would have to delay running such code until after the API has
loaded. That's what the "jsapi" callback method is about, it calls
the designated function only after the API has actually been loaded..
Your map I'm looking at now doesn't work for a different reason - but
it is still all about sequencing.
You have inline code that tries to create a GMap2 in a particular
<div> tag.
The problem arises because that code is executed immediately by the
browser as the page loads - but the <div> being looked for is defined
further down the page and the browser hasn't got that far. GMap2
creation fails because the target <div> doesn't exist.
This is why browsers provide onload events ; you can put your GMap2
creation into a function and have the browser call that function only
by <body onload='bananas()'> after it has finished reading the whole
page ; then you know the <div> has been created before you try to use
it in your function bananas().
Or in this case the initialize() function that you got rid of.
The alternative approach is to put all your inline code just before
the </body> tag
You do still need to have a <body> tag though, when you removed the
onload part you should not delete the whole line.
--
You received this message because you are subscribed to the Google Groups "Google Maps API V2" group.
To post to this group, send email to google-maps-api@googlegroups.com.
To unsubscribe from this group, send email to google-maps-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home