Displaying the infoWindow in Google Maps at the same time as the marker
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 infoWindo开发者_如何学Pythonw 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!
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 http://img534.imageshack.us/img534/1273/autoinfo.png
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: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>
精彩评论