google maps formatting text of a marker tooltip on multiple lines
Asked Answered
K

5

5

How do I insert a newline into text of a marker tooltip. I am using \n which doesn't seem to be working.

See code below:

mark = new google.maps.Marker({          
        map: map,             
        position: center,
        title:inspStates[i].name+ "\n"+"total: "+inspStates[i].totalInsp+ "\n"+ info,
        zIndex:3
});
Knuckle answered 26/7, 2011 at 13:22 Comment(1)
\n is working in internet explorer but not firefoxKnuckle
K
1

I used a customized google infoBox in place of the tooltip and it formatted properly see here: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/examples.html

Knuckle answered 27/7, 2011 at 3:33 Comment(3)
This is a bad link.Educative
I think, this would be that URL: github.com/googlemaps/v3-utility-library/tree/master/infoboxBelenbelesprit
Internet Archive: http://web.archive.org/web/20160329090524/http://google-maps-utility-library-v3.googlecode.com:80/svn/trunk/infobox/docs/examples.htmlWinterize
S
8

Use single quotes (' ') instead of double quotes (" ")it will work, like this code.

mark = new google.maps.Marker({          
            map: map,             
            position: center,
            title:inspStates[i].name+ '\n total: '+inspStates[i].totalInsp+ '\n'+ info,
            zIndex:3
    });
Snooker answered 25/6, 2016 at 6:44 Comment(0)
H
5

When using a Marker, multiline text should be in the content not title. Also instead of \n you must use html's <br/>

Hedve answered 2/4, 2014 at 1:30 Comment(2)
worked in the title for me, but you're right about <br/>Orfinger
To show a tooltip, I kept it as a title and used \n without issue.Ideational
B
4

I use \\n and this seems to work.

Blew answered 9/7, 2015 at 23:31 Comment(1)
i was using gmplot python library and this worked for meLorollas
K
1

I used a customized google infoBox in place of the tooltip and it formatted properly see here: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/examples.html

Knuckle answered 27/7, 2011 at 3:33 Comment(3)
This is a bad link.Educative
I think, this would be that URL: github.com/googlemaps/v3-utility-library/tree/master/infoboxBelenbelesprit
Internet Archive: http://web.archive.org/web/20160329090524/http://google-maps-utility-library-v3.googlecode.com:80/svn/trunk/infobox/docs/examples.htmlWinterize
M
0

If you're using FireFox, I don't think there is an easy way. The problem is explained with brilliant simplicity here by one Blake Stephens:

To quote:

The title that's automatically generated from hovering over a marker is actually the standard HTML title attribute, which works the same way as the alt tag attribute on an image. It's not exactly easy to get multiple lines on one, since browsers decide for themselves when to get the line to wrap (so really long alt texts and titles can be readable, they wrap). I don't believe it's possible to forcibly insert a line break.

However, this does not stop you from circumventing the generic title text altogether and creating your own that's completely stylable. You can attach an even to the marker for the 'mouseover' event and generate a div tag filled with your content that follows the mouse around; removing/destroying/hiding itself when the 'mouseout' event fires. That seems like the most reliable way to me.

Marrowbone answered 9/1, 2018 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.