开发者

How to escape charaters in the title of a marker in a Google Maps?

开发者 https://www.devze.com 2022-12-23 19:13 出处:网络
Say I have this piece of code: var marker = new google.maps.Marker({ position: location, title: \'Búfals\',

Say I have this piece of code:

var marker = new google.maps.Marker({
    position: location,
    title: 'Búfals',
    ma开发者_StackOverflow中文版p: 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.


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')


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.


You may want to use:

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

精彩评论

暂无评论...
验证码 换一张
取 消