Sco*_*tie 5 javascript google-maps utf-8 special-characters google-maps-api-3
我正在为一家瑞典公司构建 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
});
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在地图上的标记上时,工具提示显示为“L?s mer om...”。如果我ä在 Javascript中将“ä”更改为,工具提示将显示“ Läs mer om...”。
关键是在站点的任何其他地方使用特殊字符,直接在原始 HTML 中或由 CMS 放置的生成文本或您拥有的东西都可以正常工作。它只是在 Google Maps 实现中被破解。
同样,鉴于该网站完全是瑞典语,这可能是一个相当重要的问题。SO 常驻天才有什么好主意吗?
我试过了,在这里很有效,
\n\n如果您需要如此快地测试它,请尝试 \nconsole.log("L\\u00e4s mer om")或alert("L\\u00e4s mer om") 它会输出\n“L\xc3\xa4s mer om ”
来源 : http: //www.ietf.org/rfc/rfc4627.txt
\n\n2.5. Strings\n The representation of strings is similar to conventions used in the C\n family of programming languages. A string begins and ends with\n quotation marks. All Unicode characters may be placed within the\n quotation marks except for the characters that must be escaped:\n quotation mark, reverse solidus, and the control characters (U+0000\n through U+001F).\n\n Any character may be escaped. If the character is in the Basic\n Multilingual Plane (U+0000 through U+FFFF), then it may be\n represented as a six-character sequence: a reverse solidus, followed\n by the lowercase letter u, followed by four hexadecimal digits that\n encode the character\'s code point. The hexadecimal letters A though\n F can be upper or lowercase. So, for example, a string containing\n only a single reverse solidus character may be represented as\n "\\u005C".\n\n Alternatively, there are two-character sequence escape\n representations of some popular characters. So, for example, a\n string containing only a single reverse solidus character may be\n represented more compactly as "\\\\".\n\n To escape an extended character that is not in the Basic Multilingual\n Plane, the character is represented as a twelve-character sequence,\n encoding the UTF-16 surrogate pair. So, for example, a string\n containing only the G clef character (U+1D11E) may be represented as\n "\\uD834\\uDD1E".\nRun Code Online (Sandbox Code Playgroud)\n\n解释 :
\n\n由于标记是一个 JS 对象,因此它应该遵循上面列出的规则
\n\n{\n position: [coordinates],\n map: [map container div],\n icon: [icon image],\n title: "L\xc3\xa4s mer om "+[text from JSON] //THIS IS WHERE THE PROBLEM IS\n}\nRun Code Online (Sandbox Code Playgroud)\n\n好吧那该怎么办???\n使用<?php echo json_encode("L\xc3\xa4s mer om "); ?> 或者你的服务器端语言是什么
并将值附加到您的 JSON 对象或手动写入,然后继续!
\n