Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

JavaScript Page Load issue

Hi All,


I have written some JavaScript to resize a Google Map.

This works fine, but the map doesn't fill the DIV when the page first loads.  

If the page is resized it works.


Any suggestions where i'm going wrong?


http://www.wedding-site.org/venues/test.htm
Avatar of Blomholm
Blomholm

I think you should create the map after the page has finished loading, by setting the body's onload event. Something like:
<body onunload="GUnload()" onload="GLoad()" >
 
// and in GLoad() you put this stuff:
 
function GLoad() {
   if (GBrowserIsCompatible()) { 
 
  
          function createMarker(point,html) {
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() {
              marker.openInfoWindowHtml(html);
            });
            return marker;
          }
 
          // Display the map, with some controls and set the initial location 
          var map = new GMap2(document.getElementById("map"));
          map.addControl(new GLargeMapControl());
          map.addControl(new GMapTypeControl());
          
          // start location and zoom level, the higher the number the closer the zoom
          map.setCenter(new GLatLng(52.5,1.25),8);
        
           
                    // creates the markers
                      var point = new GLatLng(52.1943,-0.23535);
                      var marker = createMarker(point,'Location One')
                      map.addOverlay(marker);
                      var point = new GLatLng(52.11672,0.22947);
                      var marker = createMarker(point,'Location Two')
                      map.addOverlay(marker);
                      var point = new GLatLng(52.76908,-0.37751);
                      var marker = createMarker(point,'Location Three')
                      map.addOverlay(marker);
        
        } else {
          alert("Sorry, the Google Maps API is not compatible with this browser");
        }
 
}

Open in new window

Avatar of detox1978

ASKER

I've updated the file, but it's not working?
ASKER CERTIFIED SOLUTION
Avatar of Blomholm
Blomholm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that works, thanks....
The page you linked there looks good in Opera and IE at least. Map fills the div
=) np