2010-04-07 4 views
1

Quelqu'un pourrait-il m'aider à expliquer pourquoi je n'arrive pas à le faire fonctionner? Je génère correctement tous les emplacements, cependant, il ne génère pas les boîtes d'informations. Pourquoi est-ce et quelqu'un peut-il m'aider avec?Problème de tableau Google Maps openInfoWindowHTML

  var map = new GMap2(document.getElementById("map")); 
      map.addControl(new GSmallMapControl()); 
      map.addControl(new GMapTypeControl()); 
      map.setCenter(new GLatLng(47.6062, -122.3321), 8); 
      var wa_locations = new Array(new Array("Seattle", "47.6062", "-122.3321", "###-###-####", "###-###-####"), 
             new Array("Bellevue", "47.6104", "-122.2007", "###-###-####", "###-###-####"), 
             new Array("Tacoma", "47.2529", "-122.4443", "###-###-####", "###-###-####"), 
             new Array("Everett", "47.9790", "-122.2021", "###-###-####", "###-###-####")); 
      for(var i = 0; i < wa_locations.length; i++) 
      { 
       var point = new GLatLng(wa_locations[i][1], wa_locations[i][2]); 
       map.addOverlay(new GMarker(point)); 
       GEvent.addListener(point, "click", function() 
       { 
        point.openInfoWindowHtml("<b>" + wa_locations[i][0] + "</b><br/>Sales: " + wa_locations[i][3] + "<br/>Helpdesk: " + wa_locations[i][4] + ""); 
       });      
      } 

Répondre

3

Vous ajoutez un écouteur à votre point plutôt qu'à votre marqueur. De plus, à partir de votre commentaire, il semble que vous ayez un problème de fermeture de JavaScript. Vous pouvez éviter l'écouteur et la fermeture en utilisant bindInfoWindowHtml. Voici la dernière partie retouché à utiliser le marqueur et bindInfoWindowHtml:

 for(var i = 0; i < wa_locations.length; i++) 
     { 
      var point = new GLatLng(wa_locations[i][1], wa_locations[i][2]); 
      var marker = new GMarker(point); 
      marker.bindInfoWindowHtml("<b>" + wa_locations[i][0] + "</b><br/>Sales: " + wa_locations[i][3] + "<br/>Helpdesk: " + wa_locations[i][4] + ""); 
      map.addOverlay(marker); 
     } 
+0

Alors maintenant, il donne le coup d'une erreur de retour lorsque je clique sur ces objets: Message: « wa_locations [...] 0. » Est nulle ou non une object – Fo0

+0

J'ai modifié ma réponse pour supprimer la fermeture JavaScript et utiliser bindInfoWindowHtml. – Mark