I have used an iframe to create a map, and only add the src to the iframe when a certain link on my page is clicked.
This works fine. I simply put the relavent code inside an <a tag. The map source is in a separate file. Here's a sample: <table width=402 class=img align=right><td align=center> ... <iframe id="m-initial" width="480" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" style="display:none"></ iframe> ... <table><td style="padding-left:10px"> <b>Map: </b> <a style="cursor:pointer" onclick=" ... document.getElementById('m-initial').style.display='block'; document.getElementById('m-initial').style.margin='4px'; document.getElementById('m-initial').style.border='1px solid'; if (!mapInitial) {document.getElementById('m- initial').src='BM_Station_GMap.html#INDEX=QF0661&nolink=1&hide=initial&t=topo';mapInitial=true}"> <u>Interactive map for this station</u></a><br> ... </td></table> </td></table> the element id of this particular iframe is "m_initial". It's created at the top of the code fragment. Other click will display photos in the same space as the map All the map code is in the file BM_Station_GMap.html. This is a general purpose routine for my maps. The url [parameters tell it what particulars are displayed on the map. The several url paremeters pass whatever specific information needed for this particular map. the "if (!mapInitial)" statement checks if the map is already created, and if so, it doesn't create it again, just displays it. Doing it this way keeps my main routine mostly html, and the hairy javascript is in a separate rpoutine. The iframe construct effectively makes the map routine a sub routine (does anyone use the name "sub routine" any more ? (: ) Here's the whole shebang, but this is only a tiny part of the whole: http://members.bellatlantic.net/~vze2h6gy/papabear/Bay_of_Fundy_Trip.html#QF0661 If you click on the link "Map: Interactive map for this station" under the photo, and you get what I described. Works! On Apr 28, 11:47 am, Giovanni <giovan...@gmail.com> wrote: > Dear all, > apologies in advance if my question is silly, but I am relatively new > to the Google Maps API. > What I am trying to do is to load the Google API sources from inside > another javascript method, called only if a given event (i.e. onclick > of a button) occurs. The reason is because I don't want to include the > sources and the map when the web page is loaded, but only upon request > (button click). > This is my Google API script source, as usual: > > <script src="http://maps.google.com/maps?file=api&v=2& > key=ABQIAAAAaotNLvAr3kII- > cK4gDGPYxQT83kIxnWUDtibwU5Ls_0buYyM5BSRBvwwjyW4yvToTy-jJ90w3tN4AA" > type="text/javascript"> > </script> > > And here is how I am trying to load the script from another js method > (from inside an index.php page): > > <script type="text/javascript"> > var map = null; > var geocoder = null; > > function loadOnEnabled() > { > var attributesElement = document.createElement("script"); > attributesElement.setAttribute("id", "attributes"); > attributesElement.setAttribute("src", ['http://maps.google.com/maps? > file=api&v=2;amp;key=ABQIAAAAaotNLvAr3kII- > cK4gDGPYxQT83kIxnWUDtibwU5Ls_0buYyM5BSRBvwwjyW4yvToTy-jJ90w3tN4AA']); > attributesElement.setAttribute("type", "text/javascript"); > > document.documentElement.firstChild.appendChild(attributesElement); > ....................... > ....................... > > } > > But when I click the button to enable google maps, Firefox hangs up > reading maps.google.com. > > With FireBug I can see that my request generated the following error > in main.js, line2: > _mF is not defined > var m;var ba=_mF[38],ca=_mF[39],da=_mF[4...,Ta=_mF[208],Ua=_mF > [212],Va=_mF[213],Wa= > > It is clear there is something wrong in the way I pass the information > to Google with the document.createElement method, but I don't know > what. I also tried some other techniques to include Google js sources > from within my method, without any luck. > > Any help will be very very appreciated. > > Giovanni --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---