google maps v3 formatting multiple lines of content in infoWindow

trs picture trs · Jul 18, 2011 · Viewed 19k times · Source

I am trying to create an infoWindow in google maps v3 which contains multiple lines of content. However the "\n" I am using to insert a newline doesn't seem to work. What is the recommended way to insert a newline?

see code:

//set content of infoWindow
window.setContent(inspStates[i].name+ "\n"+"total: "+inspStates[i].totalInsp+ "\n"+ info);

Answer

Jason Gennaro picture Jason Gennaro · Jul 18, 2011

The easiest thing to do it wrap the content in a div or in a p and then use <br /> for line breaks.

So something like

//set content of infoWindow
window.setContent("<p>" + inspStates[i].name + "<br />" + 
                  "total: " + inspStates[i].totalInsp + "<br />" + info + 
                  "</p>");