views:

88

answers:

2

Hi all, I have developed a Google Map page which displays a marker where I tell it to. If you click the marketr, the infoWindow pops up. However, I was wondering if anybody knows how to open the infoWindow and display the marker at the same time? (as in onload)

Here's the page: http://www.sportingemporium.com/map_test3.htm

This seems like a straight forward exercise but I have searched for hours without finding a solution!

Any assistance would be great!

+2  A: 

You simply need to call marker.openInfoWindowHtml() to open the info window imperatively:

var map = new GMap2(document.getElementById("map"));
var point = new GLatLng(53.3407791, -6.2596385);

map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(point, 16);

// Set up three markers with info windows 
var html = 'South Anne Street,<br />Dublin 2, Ireland';
var marker = new GMarker(point);

map.addOverlay(marker);
marker.openInfoWindowHtml(html);     // This opens the info window automatically

GEvent.addListener(marker, "click", function() {
   marker.openInfoWindowHtml(html);
});

openInfoWindowHtml

Daniel Vassallo
That worked a treat Daniel! Thanks a million!
Decbrad
A: 

Hi Steve, here's the code! ...as you can see the page load block is already occupied by GUnload() Is there anywhere else that I could put that call?

<script type="text/javascript">
//<![CDATA[

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());
  map.setCenter(new GLatLng(53.3407791,-6.2596385),16);

  // Set up three markers with info windows 

  var point = new GLatLng(53.3407791,-6.2596385);
  var marker = createMarker(point,'<img src="images/casino-on-map.jpg" width="125" height="125" hspace="10" align="left"><strong>The Sporting Emporium</strong><br/><p>Annes Lane, <br />South Anne Street,<br />Dublin 2, Ireland<br /><br />(+353 1) 7030 600<br /><a href="mailto:[email protected]">[email protected]</a></p>')
  map.addOverlay(marker);

}

// display a warning if the browser was not compatible
else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

//]]>
</script>
Decbrad
`GUnload()` uses the `onunload` event not the `onload`, so the map can still be loaded from there.
Daniel Vassallo
Decbrad Daniel has got the perfect solution I suggest you accept his solution.
Steve Robillard