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<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> *{ margin: 0; padding: 0; }
html, body, #map{
width: 100%;
height: 100%;
}
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=es"></script> <script type="text/javascript"> window.onload = function(){
var options = {
zoom: 9
, center: new google.maps.LatLng(18.2, -66.4)
, mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
var place = new Array();
place['San Juan'] = new google.maps.LatLng(18.465, -66.105);
place['Mayagüez'] = new google.maps.LatLng(18.215, -67.14);
place['Ponce'] = new google.maps.LatLng(18.025, -66.615);
place['Fajardo'] = new google.maps.LatLng(18.336, -65.65);
place['Culebras'] = new google.maps.LatLng(18.315, -65.3);
place['Vieques'] = new google.maps.LatLng(18.125, -65.44);
for(var i in place){
var marker = new google.maps.Marker({
position: place[i]
, map: map
, title: i
});
google.maps.event.addListener(marker, 'click', function(){
var popup = new google.maps.InfoWindow();
popup.setContent('Lugar: ' + i);
popup.open(map, marker);
})
}
};
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<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> *{ margin: 0; padding: 0; }
html, body, #map{
width: 100%;
height: 100%;
}
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=es"></script> <script type="text/javascript"> window.onload = function(){
var options = {
zoom: 9
, center: new google.maps.LatLng(18.2, -66.4)
, mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
var place = new Array();
place['San Juan'] = new google.maps.LatLng(18.465, -66.105);
place['Mayagüez'] = new google.maps.LatLng(18.215, -67.14);
place['Ponce'] = new google.maps.LatLng(18.025, -66.615);
place['Fajardo'] = new google.maps.LatLng(18.336, -65.65);
place['Culebras'] = new google.maps.LatLng(18.315, -65.3);
place['Vieques'] = new google.maps.LatLng(18.125, -65.44);
for(var i in place){
var marker = new google.maps.Marker({
position: place[i]
, map: map
, title: i
});
(function(i, marker){
google.maps.event.addListener(marker, 'click', function(){
var popup = new google.maps.InfoWindow();
popup.setContent('Lugar: ' + i);
popup.open(map, marker);
})
})(i, marker);
}
};