CodeIgniter Forums
using javascript and body onload - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: using javascript and body onload (/showthread.php?tid=22608)



using javascript and body onload - El Forum - 09-15-2009

[eluser]boony[/eluser]
Hi Guys,

Just a quick question. I'm trying to implement a google map function in my project. I'm just adding the javascript in the head section

Code:
[removed][removed]
    [removed]
      function initialize() {
        var latlng = new google.maps.LatLng(<?php echo $centerLat;?>, <?php echo $centerLng;?>);
        var myOptions = {
          zoom: 11,
          center: LatLng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }
    
    [removed]
and then using
Code:
<body>

But for some reason the map is not loading. Other small tests indicate everything seems to be working ok so I got a feeling its not doing the body onload bit??? Any ideas??

Thanks


using javascript and body onload - El Forum - 09-15-2009

[eluser]boony[/eluser]
Hmm sorry the body tag should read <body>


using javascript and body onload - El Forum - 09-15-2009

[eluser]boony[/eluser]
damn...body onload initialize()

Hope this works


using javascript and body onload - El Forum - 09-15-2009

[eluser]Geoffrey[/eluser]
Well first off, you're setting a variable of latlng but you're calling it as LatLng for the center.

I assume the body tag is <body onload="initialize()">

I don't see any html but I also assume there's an html element somewhere with an id of map_canvas?

<div id="map_canvas"></div>

and that you're calling the google map javascript correctly.


using javascript and body onload - El Forum - 09-15-2009

[eluser]boony[/eluser]
Hello, thanks for taking the time to look at my little problem. It seems that the problem must have been related to a GOOGLE thingy and not the code. I got it all working 6-7hours later but have no idea why (nothing in the code changed)

ho hum, just another one of life's little mysteries....:gulp: