Vous avez trouvé ce tutoriel intéressant ? Recommandez le en cliquant sur le bouton +1    

Ajouter une info-bulle sur une carte Google Maps

Tutoriel publié le Mis à jour le
Tutoriel en Français

Cette fonction permet d'ajouter une infobulle sur une carte Google Maps

addInfoWindow

  • Paramètres spécifiques :
    • open <booléen> : Ouvre l'info bulle
    • anchor google.maps.Marker : marqueur à associer à l'info bulle.
  • Nom de stockage : infowindow
  • Résultat du Callback : google.maps.InfoWindow

Cet exemple ajoute une info bulle (ou infowindow), et applique la fonction google.maps.InfoWindow.setContent avec un argument chaîne (exemple d'utilisation d' apply).

  
$('#test').gmap3(
	{
		action: 'addInfoWindow',
		address: "place de l'étoile, Paris",
		map:{
			center: true,
			zoom: 14
		},
		infowindow:{
			options:{
				content: 'Hello World !'
			},
			events:{
				closeclick: function(infowindow, event){
					alert('closing : ' + $(this).attr('id') + ' : ' + infowindow.getContent());
				}
			},
			apply:[
				{
					action:'setContent', 
					args:[
						'Placez votre contenu ici !'
					]
				}
			]
		}
	}
);

Carte avec addInfoWindow

Code complet avec addInfoWindow

<!DOCTYPE html>
<html lang="fr">
	<head>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
		<meta charset="UTF-8"/>
		<title>Votre titre de page</title>
		<style type="text/css">
			html { height: 100% }
			body { height: 100%; margin: 0px; padding: 0px }
			#maCarte{
				height: 350px;
				width: 100%;
			}
		</style>
		<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
		<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
		<script type="text/javascript" src="http://www.votredomaine.fr/js/gmap3.js"></script>
		<script type="text/javascript"> 
			$(function(){
				$('#maCarte').gmap3(
					{
						action: 'addInfoWindow',
						address: "place de l'étoile, Paris",
						map:{
							center: true,
							zoom: 14
						},
						infowindow:{
							options:{
								content: 'Hello World !'
							},
							events:{
								closeclick: function(infowindow, event){
									alert('closing : ' + $(this).attr('id') + ' : ' + infowindow.getContent());
								}
							},
							apply:[
								{
									action:'setContent', 
									args:[
										'Placez votre contenu ici !'
									]
								}
							]
						}
					}
				);
			});
		</script>
	</head>
	
	<body>
		<div id="maCarte"></div>
	</body>
</html>

 

Source

addInfoWindow

Résumé

GMap3 Plugin JQuery : addInfoWindow

addInfoWindow