如何转义 Google 地图中标记标题中的字符?

发布于 2024-08-26 11:59:04 字数 418 浏览 4 评论 0原文

假设我有这段代码:

var marker = new google.maps.Marker({
    position: location,
    title: 'Búfals',
    map: map
});

这会按预期创建一个标记,但如果我将鼠标悬停在其上,我看不到“Búfals”
正如我所期望的(相反我看到了 html 代码)。

这没有任何区别:

var marker = new google.maps.Marker({
    position: location,
    title: unescape('Búfals'),
    map: map
});  

有什么想法吗?

谢谢。

Say I have this piece of code:

var marker = new google.maps.Marker({
    position: location,
    title: 'Búfals',
    map: map
});

This creates a marker as expected but if I hover the mouse over it I don’t see 'Búfals'
as I would expect (instead I see the html code).

This doesn't make any difference:

var marker = new google.maps.Marker({
    position: location,
    title: unescape('Búfals'),
    map: map
});  

Any ideas?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

み格子的夏天 2024-09-02 11:59:04

这可能有点矫枉过正,但它确实有效:

function decode(txt){
  var sp = document.createElement('span');
  sp.innerHTML = txt;
  return sp.innerHTML;
}

decode('Búfals')

This may be an overkill but it works:

function decode(txt){
  var sp = document.createElement('span');
  sp.innerHTML = txt;
  return sp.innerHTML;
}

decode('Búfals')
李不 2024-09-02 11:59:04

与 Daniel 的建议类似,您可以尝试使用您要显示的字符的 unicode 值,在您的情况下它将是 \u09fa

Similar to what Daniel suggested, you could try using the unicode value for the character you're trying to display, in your case it would be \u09fa.

南汐寒笙箫 2024-09-02 11:59:04

您可能想使用:

var marker = new google.maps.Marker({
   position: myLatlng,
   map: map,
   title: unescape('B%FAfals')
});

You may want to use:

var marker = new google.maps.Marker({
   position: myLatlng,
   map: map,
   title: unescape('B%FAfals')
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文