Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google maps v3 formatting multiple lines of content in infoWindow

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);
like image 328
trs Avatar asked Jul 18 '11 17:07

trs


2 Answers

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>");
like image 55
Jason Gennaro Avatar answered Nov 08 '22 01:11

Jason Gennaro


Use HTML for the content, and put each line in its own paragraph. Line separation helps with readability, especially if any of the lines is long enough to wrap.

window.setContent(
    "<p>" + inspStates[i].name + "</p>" + 
    "<p>Total: " + inspStates[i].totalInsp + "</p>" +
    "<p>" + info + "</p>");
like image 32
Edward Brey Avatar answered Nov 08 '22 02:11

Edward Brey