Welcome Guest, Not a member yet? Register   Sign In
using javascript and body onload
#1

[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
#2

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

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

Hope this works
#4

[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.
#5

[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:




Theme © iAndrew 2016 - Forum software by © MyBB