2010-05-06 9 views
2

J'ai développé une page Google Map qui affiche un marqueur où je le dis. Si vous cliquez sur le marketr, l'infoWindow apparaît. Cependant, je me demandais si quelqu'un sait comment ouvrir l'infoWindow et afficher le marqueur en même temps? (Comme dans onload)Afficher la fenêtre info dans Google Maps en même temps que le marqueur

est ici la page: http://www.sportingemporium.com/map_test3.htm

Cela semble être un exercice avant droit, mais je l'ai cherché pendant des heures sans trouver une solution!

Toute aide serait géniale!

+0

Tu ne peux pas appeler l'événement clic après avoir affiché le marqueur? –

+0

Salut Steve, merci pour la réponse. Pour autant que je puisse voir, l'événement de clic est le problème. Je ne peux pas attendre que l'utilisateur clique sur le marqueur. L'infowindow doit s'ouvrir au chargement de la page, à moins que je ne me trompe! C'est tard! Decbrad – Decbrad

+0

cela aiderait à voir le code, mais ce que je suggère est d'ajouter un appel à l'événement de clic dans votre bloc de chargement de la page –

Répondre

3

Il vous suffit d'appeler marker.openInfoWindowHtml() pour ouvrir la fenêtre info impérieusement:

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

+0

Cela a fonctionné un festin Daniel! Merci un million! – Decbrad

+0

il doit être retiré sur api v3 .. il n'a pas fonctionné pour moi .. – dvdmn

0

est ici le code! ... comme vous pouvez le voir, le bloc de chargement de la page est déjà occupé par GUnload() Y a-t-il d'autres endroits où je pourrais mettre cet appel?

<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> 
+0

'GUnload()' utilise l'événement 'onunload' pas le' onload', de sorte que la carte peut encore être chargée à partir de là. –

+0

Decbrad Daniel a la solution parfaite Je vous suggère d'accepter sa solution. –

Questions connexes