Ver Mensaje Individual
  #7 (permalink)  
Antiguo 03/04/2011, 12:24
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Clausura (clousure) y/o Encapsulación

Gracias zero.

Gmaps no lo trabaja de esa forma, sino que tienes que declararlo. Para que me entiendas mejor, te posteo un ejemplo sencillo de Gmaps
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4.     <title>test</title>
  5.     <style>
  6.     *{ margin: 0; padding: 0; }
  7.     html, body, #map{
  8.         width: 100%;
  9.         height: 100%;
  10.     }
  11.     </style>
  12.     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language=es"></script>
  13.     <script type="text/javascript">
  14.     window.onload = function(){
  15.         var options = {
  16.             zoom: 9
  17.             , center: new google.maps.LatLng(18.2, -66.4)
  18.             , mapTypeId: google.maps.MapTypeId.ROADMAP
  19.         };
  20.  
  21.         var map = new google.maps.Map(document.getElementById('map'), options);
  22.  
  23.         var place = new Array();
  24.         place['San Juan'] = new google.maps.LatLng(18.465, -66.105);
  25.         place['Mayagüez'] = new google.maps.LatLng(18.215, -67.14);
  26.         place['Ponce'] = new google.maps.LatLng(18.025, -66.615);
  27.         place['Fajardo'] = new google.maps.LatLng(18.336, -65.65);
  28.         place['Culebras'] = new google.maps.LatLng(18.315, -65.3);
  29.         place['Vieques'] = new google.maps.LatLng(18.125, -65.44);
  30.  
  31.         for(var i in place){
  32.             var marker = new google.maps.Marker({
  33.                 position: place[i]
  34.                 , map: map
  35.                 , title: i
  36.             });
  37.  
  38.             google.maps.event.addListener(marker, 'click', function(){
  39.                 var popup = new google.maps.InfoWindow();
  40.                 popup.setContent('Lugar: ' + i);
  41.                 popup.open(map, marker);
  42.             })
  43.         }
  44.     };
  45.     </script>
  46. </head>
  47.     <div id="map"></div>
  48. </body>
  49. </html>
De esta forma tiene un problema es que se muestra siempre el último seleccionado. Como todavía no me he puesto a observar con detenimiento el código de Panino, no sé como implementarlo, pero la forma más sencilla que vi como lograr que eso funcione correctamente es así
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4.     <title>test</title>
  5.     <style>
  6.     *{ margin: 0; padding: 0; }
  7.     html, body, #map{
  8.         width: 100%;
  9.         height: 100%;
  10.     }
  11.     </style>
  12.     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language=es"></script>
  13.     <script type="text/javascript">
  14.     window.onload = function(){
  15.         var options = {
  16.             zoom: 9
  17.             , center: new google.maps.LatLng(18.2, -66.4)
  18.             , mapTypeId: google.maps.MapTypeId.ROADMAP
  19.         };
  20.  
  21.         var map = new google.maps.Map(document.getElementById('map'), options);
  22.  
  23.         var place = new Array();
  24.         place['San Juan'] = new google.maps.LatLng(18.465, -66.105);
  25.         place['Mayagüez'] = new google.maps.LatLng(18.215, -67.14);
  26.         place['Ponce'] = new google.maps.LatLng(18.025, -66.615);
  27.         place['Fajardo'] = new google.maps.LatLng(18.336, -65.65);
  28.         place['Culebras'] = new google.maps.LatLng(18.315, -65.3);
  29.         place['Vieques'] = new google.maps.LatLng(18.125, -65.44);
  30.  
  31.         for(var i in place){
  32.             var marker = new google.maps.Marker({
  33.                 position: place[i]
  34.                 , map: map
  35.                 , title: i
  36.             });
  37.  
  38.             (function(i, marker){
  39.                 google.maps.event.addListener(marker, 'click', function(){
  40.                     var popup = new google.maps.InfoWindow();
  41.                     popup.setContent('Lugar: ' + i);
  42.                     popup.open(map, marker);
  43.                 })
  44.             })(i, marker);
  45.         }
  46.     };
  47.     </script>
  48. </head>
  49.     <div id="map"></div>
  50. </body>
  51. </html>
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos