javascript 谷歌地图标记 API 标记的标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19279199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
title of a marker of google map marker API
提问by shiro
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?
我尝试更改部分标题的颜色,但看起来标题选项不采用 html 格式。我怎样才能让它工作?
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
});
回答by qwertmax
you must use InfoWindow object
您必须使用 InfoWindow 对象
see this doc google map api
看这个文档谷歌地图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);
});
回答by geocodezip
A "title" is a tooltip that is automatically created for the google.maps.Markerobject. 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.
“标题”是为google.maps.Marker对象自动创建的工具提示。它不支持 HTML 标记。如果你想创建一个不同于默认的,你可以,但它会是自定义的。
See this postfor one custom tool tip option (a google searchfound 2 posts describing them).