Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InfoWindow with Html in google maps

I am using the following code to create an infowindow for the markers in the map. In the message variable i am sending a string with Html inside it. When i run my application inside the infobox i am getting the string without the Html styling. For example inside the box i see blah blah blah ... Does anyone know how to get the infobox with html styling inside?

 function attachSecretMessage(marker, number) {

         var infowindow  = new google.maps.InfoWindow(
      { content: message[number],
          size: new google.maps.Size(50, 50)
      });
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map1, marker);
      });
like image 638
user1292656 Avatar asked Oct 03 '12 06:10

user1292656


People also ask

What is InfoWindow in Google map?

An InfoWindow displays content (usually text or images) in a popup window above the map, at a given location. The info window has a content area and a tapered stem. The tip of the stem is attached to a specified location on the map. Info windows appear as a Dialog to screen readers.

How do I change the background color of InfoWindow in Google Maps?

addListener(marker, 'mouseover', function() { infoWindow. setContent(html); infoWindow. open(map, marker); //infoWindow. setStyle("background-color: red"); });

How do I open multiple Infowindows in Google Maps?

By assigning the infowindow to a marker property, each marker can have it's own infowindow. This was how I approached the problem, with the relevant sample code. //create a marker object first, or instantiate it by passing a JSON to the constructor. //this can be done inside a for loop var infowindow = new google.


1 Answers

Put all your custom html code in a variable and assign the value to "content" !!!

    var contentString = 
                '<div id="content" style="width:400px; background-color:red;">' +
                'My Text comes here' + 
                '</div>';

   var infowindow = new google.maps.InfoWindow({
            content: contentString,
            maxWidth: 400
        });
like image 102
thomasbabuj Avatar answered Sep 28 '22 19:09

thomasbabuj