Partage
  • Partager sur Facebook
  • Partager sur Twitter

[google map API v3] info windows

afficher une info windows sur un marqueur

Sujet résolu
    26 août 2010 à 9:36:46

    Bonjour à tous,

    Voila, j'ai une page web qui affiche une carte google map en utilisant l'API v3, et je souhaite mettre des info windows sur les marqueurs qui sont sur la carte.

    Tout marche: la carte s'affiche, les marqueur aussi, mais quand je clique sur un marqueur pour afficher l'info bulle, rien ne se passe, et il m'affiche une erreur comme quoi 'undefined' a la valeur null ou n'est pas un objet. :(

    Pour plus de compréhension, voici mon code (fonctionnel si vous le copiez collez):


    carte.html
    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
    <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='fr'>
    	<head>
    		<link rel='stylesheet' type='text/css' href='/Styles/Cartes.css'>
    		<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
    		<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script>
    		<script type='text/javascript' src='carte.js'></script>
    	</head>
    	<body>
    	<h1>carte</h1>
    		<script>
    			window.onload = function() {
    				InitTab(3);
    				var maCarte = new Carte(5, 48, 2, 'ROADMAP');
    				maCarte.addMarker('Réaménagement', 'CHERREAU_TDF', 48.203132764048, 0.6832809921675, 0, 0);
    				maCarte.addMarker('Réaménagement', 'SARGE_LES_LE_MANS', 48.019457654839, 0.2192570160332, 0, 1);
    				maCarte.addMarker('Réaménagement', 'LA_POMMERAYE_TDF', 47.323408639565, -0.91166882239994, 0, 2);
    				maCarte.addMarker('Réaménagement', 'ANGERS_ROOSEVELT', 47.469944144984, -0.5508915944787, 0, 3);
    				maCarte.addMarker('Réaménagement', 'BONNETABLE', 48.188296973018, 0.43728106285315, 1, 0);
    				maCarte.addMarker('Réaménagement', 'ST_CALAIS', 47.91206068472, 0.73467043252774, 1, 1);
    				maCarte.addMarker('Réaménagement', 'CHATEAU_GONTIER_TDF', 47.81721570879, -0.71584628826639, 1, 2);
    				maCarte.addMarker('Réaménagement', 'LE_TREMBLAY_TDF', 47.65991577969, -1.0915628223523, 1, 3);
    				maCarte.addMarker('Réaménagement', 'ROCHEFORT_SUR_LOIRE_TDF', 47.336097058737, -0.64580824843965, 2, 0);
    				maCarte.addMarker('Réaménagement', 'LE_VIEUX_MANS', 48.003481381261, 0.19161591289149, 2, 1);
    				maCarte.addMarker('Réaménagement', 'LAVAL_CENTRE_TDF', 48.075451572907, -0.77517230237712, 2, 2);
    				}
    		</script>
    		<br/>
    		<div id='map' class='map' style='width:85%; height:75%' >
    		</div>
    	</body>
    </html>
    




    carte.js
    var carte;	//declaration de la carte
    var bounds;	//limite de la carte en fonciton des marqueurs
    var marker = new Array(); //tableau contenant tout les marqueurs
    var nbMarker = new Array();
    var tabCoord;
    
    function InitTab(i)
    {
    	for (a = 0; a < i; a++)
    	{
    		
    		marker[a] = new Array();
    	}
    }
    
    function Carte	(optZoom,Lattitude,Longitude,optMapTypeId)
    {
    	var optCenterMap = new google.maps.LatLng(Lattitude, Longitude);
    	var mapType = google.maps.MapTypeId[optMapTypeId];
    	var options =
    		{
    			center: 				optCenterMap,
    			mapTypeId: 				mapType,
    			zoom: 					optZoom
    		};
    	this.carte = new google.maps.Map(document.getElementById("map"), options);
    	bounds = new google.maps.LatLngBounds();
    }
    
    Carte.prototype.addMarker = function 	(Window,Nom,Latitude,Longitude,i,j)
    {
    	
    	nbMarker[i] = j;
    	var info = new google.maps.InfoWindow(
    			{
    				content: Window
    			});
    	var optCenterMarker = new google.maps.LatLng(Latitude, Longitude);
    	bounds.extend(optCenterMarker);
    	marker[i][j] = new google.maps.Marker(
    		{
    			position : 	optCenterMarker,
    			title : 	Nom,
    			map : 		this.carte
    		});
    	google.maps.event.addListener(marker[i][j], 'click', function()
    		{
    			info.open(this.carte, marker[i][j]);
    		});
    	this.carte.fitBounds(bounds);
    };
    
    • Partager sur Facebook
    • Partager sur Twitter
      26 août 2010 à 11:42:41

      info.open, je ne vois ta variable info défini nul-part.
      • Partager sur Facebook
      • Partager sur Twitter
        26 août 2010 à 12:34:28

        elle est définit ici:

        var info = new google.maps.InfoWindow(
        			{
        				content: Window
        			});
        


        Quoiqu'il en soit, j'ai résolut le problème, je ne sais pas trop pourquoi mais il n'aime pas les this.

        J'ai donc enlevé tout les this. et ça fonctionne correctement...
        • Partager sur Facebook
        • Partager sur Twitter

        [google map API v3] info windows

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown