<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.619108, lng: -58.43131},
zoom: 15
});
var tienda_de_cafe={lat:-34.619214,lng:-58.434158};
var marker =new google.maps.Marker(
{
position: tienda_de_cafe,
map:map,
title: 'La Tienda de Cafe!'
});
}
</script>
cuando pasemos el mouse por arriba del Mark (globo rojo) se mostrara el texto "La Tienda de Cafe!"
podemos ademas agregar information sobre ese punto y que aparezca cuando clickeamos sobre el.
var infoWinfow=new google.maps.InfoWindow(
         {content:'Vení a conocernos, disfrutá de la experiencia que tenemos para brindarte. Y llevate a tu casa el mejor café del mundo. '});
        marker.addListener('click',function(){
         infoWinfow.open(map,this);
        });
Se puede hacer lo mismo para varios puntos a la vez
var locations=[{title:'punto 1',location:{lat:-34.622628,lng:-58.43234}},{title:'punto 2',location:{lat:-34.615105,lng:-58.428648} },{title:'punto 3',location:{lat:-34.615928,lng:-58.430953}}
    ];
        var infoWinfowCommon=new google.maps.InfoWindow();
    for (var i = locations.length - 1; i >= 0; i--) {
     var marker =new google.maps.Marker(
     {
      position: locations[i].location,
      map:map,
      title: locations[i].title
     });
            populateInfoWindow(marker,infoWinfowCommon);
    }
donde:
function populateInfoWindow(marker,infoWindow){
    if(infoWindow.marker!=marker){
        marker.addListener('click',function(){
             infoWindow.marker = marker;
            infoWindow.setContent(marker.title);
         infoWindow.open(map,marker);
         infoWindow.addListener('closeclick',function(){
                     this.marker=null;
         });
         }); 
    }
   }


 
 
 
No hay comentarios:
Publicar un comentario