How to show an image in the Marker information window?

Asked

Viewed 435 times

2

By clicking on a marker created with the Google Maps API, you can add an information window, which is what the code below does:

google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent("image.png");
      infowindow.open(map, marker);
    }
  })(marker, i));

How it is reproduced:

inserir a descrição da imagem aqui

But I would like to show instead in the balloon the text of the image, image.png , would like to view the image in fact. How to display an image in the Marker information window?

1 answer

2


According to the own documentation google, you can simply put the image tag in a string and pass it to the content of infowindow.

ex:

var contentString = '<img src="image.png">';

var infowindow = new google.maps.InfoWindow({
    content: contentString
  });

Follows a fiddle made available in the documentation of how to do this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.