Displaying an info window in Google Maps along with a marker

I have designed a Google Map page that displays the marker I'm talking to. If you click on marketr the infoWindow will appear. However, I was wondering if anyone knows how to open the info window and display the marker at the same time? (as when loading)

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

This looks like a straight forward exercise, but I've searched for hours without finding a solution!

Any help would be great!

+2


a source to share


2 answers


You just 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 http://img534.imageshack.us/img534/1273/autoinfo.png

+3


a source


here is the code! ... as you can see, the page load block is already occupied by GUnload () Is there somewhere else I could put this 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:info@thesportingemporium.com">info@thesportingemporium.com</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>

      

0


a source







All Articles