Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

title of a marker of google map marker API

I try to change the color of part of the title, but look like the title option does not take html format. How can I make it work?

Thank you

var testtitle = '<font color="green">This is some text!</font> another text';   

var marker = new google.maps.Marker({
position: location,
title: testtitle,
map: map
});
like image 993
shiro Avatar asked Feb 03 '26 17:02

shiro


2 Answers

you must use InfoWindow object

see this doc google map api

var infowindow = new google.maps.InfoWindow({
    content: "<span>any html goes here</span>"
});

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: 'Uluru (Ayers Rock)'
});

google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
});
like image 181
qwertmax Avatar answered Feb 06 '26 06:02

qwertmax


A "title" is a tooltip that is automatically created for the google.maps.Marker object. It doesn't support HTML markup. If you want to create one that is different from the default, you can, but it would be custom.

See this post for one custom tool tip option (a google search found 2 posts describing them).

like image 42
geocodezip Avatar answered Feb 06 '26 06:02

geocodezip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!