Google Maps v3 - 在标记标题中使用重音字符

时间:2010-11-30 10:52:01

标签: javascript google-maps utf-8 google-maps-api-3 special-characters

我正在为瑞典公司构建Google地图实施,因此该语言有很多用途ä,å和ö。我可以正确显示特殊字符(网站字符集是UTF-8),除了每个地图标记的“标题”属性。我的标记代码是(你可以忽略方括号中的所有内容):

var marker = new google.maps.Marker({
    position: [coordinates],
    map: [map container div],
    icon: [icon image],
    title: "Läs mer om "+[text from JSON]  //THIS IS WHERE THE PROBLEM IS
});

当我将鼠标悬停在地图上的标记上时,工具提示会显示为“L smerom om ...”。如果我在Javascript中将“ä”更改为ä,则工具提示会显示“Läs mer om...”。

踢球者是在网站的任何其他位置使用特殊字符,可以是直接在原始HTML中,也可以是由CMS放置的生成文本,或者你可以使用什么工作。它在Google Maps实施中只是 它正在崩溃。

同样,鉴于该网站完全采用瑞典语,这可能是一个相当重要的问题。来自SO居民天才的任何好主意?

1 个答案:

答案 0 :(得分:3)

我试一试,它在这里工作,

如果您需要快速测试,请尝试 它会输出console.log("L\u00e4s mer om")alert("L\u00e4s mer om")  “Läsmerom om”

来源:http://www.ietf.org/rfc/rfc4627.txt

2.5.  Strings
   The representation of strings is similar to conventions used in the C
   family of programming languages.  A string begins and ends with
   quotation marks.  All Unicode characters may be placed within the
   quotation marks except for the characters that must be escaped:
   quotation mark, reverse solidus, and the control characters (U+0000
   through U+001F).

   Any character may be escaped.  If the character is in the Basic
   Multilingual Plane (U+0000 through U+FFFF), then it may be
   represented as a six-character sequence: a reverse solidus, followed
   by the lowercase letter u, followed by four hexadecimal digits that
   encode the character's code point.  The hexadecimal letters A though
   F can be upper or lowercase.  So, for example, a string containing
   only a single reverse solidus character may be represented as
   "\u005C".

   Alternatively, there are two-character sequence escape
   representations of some popular characters.  So, for example, a
   string containing only a single reverse solidus character may be
   represented more compactly as "\\".

   To escape an extended character that is not in the Basic Multilingual
   Plane, the character is represented as a twelve-character sequence,
   encoding the UTF-16 surrogate pair.  So, for example, a string
   containing only the G clef character (U+1D11E) may be represented as
   "\uD834\uDD1E".

解释:

因为标记是JS对象,所以它应该遵循上面列出的规则

{
    position: [coordinates],
    map: [map container div],
    icon: [icon image],
    title: "Läs mer om "+[text from JSON]  //THIS IS WHERE THE PROBLEM IS
}

好吧那该怎么办??? 使用<?php echo json_encode("Läs mer om "); ?>或您的服务器端语言

并将值附加到您的JSON对象或手动编写并继续!