将地图本地化
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以通过下列方式针对特定国家或地区自定义地图:
- 更改默认语言设置。
- 指定区域代码,这样系统就会根据所指定的国家或地区来改变地图的运行方式。
语言本地化
默认情况下,在地图上显示控件名称、版权声明、行车路线和标签等文本信息时,Maps JavaScript API 会使用用户在浏览器中指定的首选语言设置。在大多数情况下,最好遵循浏览器的设置。不过,如果您希望 Maps JavaScript API 忽略浏览器的语言设置,可以在加载 Maps JavaScript API 代码时向 <script>
标记添加一个 language
参数,强制浏览器以特定语言显示信息。
language
参数会影响控件名称、版权声明、行车路线和控件标签,以及对服务请求的响应。但对服务的影响则不这么明显。例如,在对街道级地址进行地理编码时,系统会以您请求的语言返回国家/地区名称,但地址的其余部分则取决于您要进行地理编码的位置。另一方面,邮政和政区结果会以请求的语言返回。不妨试用此演示版应用,体验一下在更新 language
参数时地图上发生的变化。
下例以日语显示地图,并将区域设置为日本:
<script async
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async®ion=JP&language=ja&callback=initMap">
</script>
查看示例。
在设置地图的语言时,一定要考虑同时设置区域。这有助于确保您的应用遵守当地法律。
注意:按照上面所示的方式加载该 API 时,无论用户的偏好设置如何,地图都会为所有用户使用日语。因此,在设置此选项之前,请确保您确实希望如此。
Maps JavaScript API 还为包含左至右 (LTR) 和右至左 (RTL) 两种语言字符的双向 (Bidi) 文本提供原生支持。例如,阿拉伯语、希伯来语和波斯语就属于 RTL 语言。通常,您应该通过向页面的 <html>
元素添加 dir='rtl'
来指定页面采用 RTL 语言,以便正确渲染。下例使用阿拉伯语控件来渲染埃及开罗的地图:
<script async
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async®ion=EG&language=ar&callback=initMap">
</script>
查看示例
请参阅支持的语言列表。请注意,我们会经常添加新语言,因此该列表可能并非详尽无遗。
区域本地化
如果您想更改应用以使其提供不同的地图图块,或者使应用具有偏向(例如,使地理编码结果偏向于相应区域),请在加载 Maps JavaScript API 代码时向 <script>
标记添加 region
参数。
您是 Maps JavaScript API 应用的开发者,我们建议您始终设置 region
参数,因为设置 region
后,各种服务(例如地点自动补全)往往能够提供更好的结果。您也有责任确保在部署应用的国家/地区进行正确的区域本地化,以确保您的应用符合当地法律。
region
参数接受 Unicode 地区子标记标识符,后者(通常)与国家/地区代码一级的顶级域名 (ccTLD) 存在一对一映射关系。除了某些明显的例外情况之外,大多数 Unicode 区域标识符都与 ISO 3166-1 alpha-2 代码完全一致。例如,英国的 ccTLD 为“uk”(对应于域名 .co.uk
),但其区域标识符为“GB”。如需了解支持的地区,请参阅 Google Maps Platform 覆盖范围详细信息。不妨试用此演示版应用,体验一下在更新 region
参数时地图上发生的变化。
例如,以下脚本标记针对英国对地图进行了本地化:
<script async
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async®ion=GB&callback=initMap">
</script>
下面的示例显示了两张地图,一张根据设置为 US
(美国)的 region
将“托莱多”地理编码为“俄亥俄州托莱多”,而另一张根据设置为 ES
(西班牙)的 region
使结果偏向于“西班牙托莱多”。
欢迎查看美国示例和西班牙示例。
本地化演示
在设置地图的语言时,一定要考虑同时设置区域。在下面的演示中,您能够以自己选择的语言和区域加载地图。
以全屏模式观看此演示。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-06。
[null,null,["最后更新时间 (UTC):2025-08-06。"],[[["\u003cp\u003eCustomize your map by adjusting the default language and specifying a region code for tailored behavior.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the \u003ccode\u003elanguage\u003c/code\u003e parameter in the script tag to display map information in a specific language, overriding browser settings if needed.\u003c/p\u003e\n"],["\u003cp\u003eApply the \u003ccode\u003eregion\u003c/code\u003e parameter in the script tag to refine map tiles, bias application results, and ensure compliance with local laws.\u003c/p\u003e\n"],["\u003cp\u003eFor optimal results and legal adherence, consider setting both \u003ccode\u003elanguage\u003c/code\u003e and \u003ccode\u003eregion\u003c/code\u003e parameters when localizing your map.\u003c/p\u003e\n"]]],["To customize a map, specify a `language` and `region` parameter in the `\u003cscript\u003e` tag when loading the Maps JavaScript API. The `language` parameter sets the display language for controls, directions, and service responses, overriding the browser's default. The `region` parameter alters map tiles and biases service results, like geocoding. Setting both is crucial for legal compliance and service accuracy. For example, you can set the language to Japanese and the region to Japan by setting `language=ja` and `region=JP`.\n"],null,["You can customize your map for a specific country or region in the following\nways:\n\n- Change the default language settings.\n- Specify a region code, which alters the map's behavior based on a given country or territory.\n\nLanguage localization\n\nBy default, the Maps JavaScript API uses the user's preferred\nlanguage setting as specified in the browser, when displaying textual\ninformation such as the names for controls, copyright notices, driving\ndirections and labels on maps. In most cases, it's preferable to respect the\nbrowser setting. However, if you want the\nMaps JavaScript API to ignore the browser's\nlanguage setting, you can force it to display information in a particular\nlanguage by adding a `language` parameter to the\n`\u003cscript\u003e` tag when loading the\nMaps JavaScript API code.\n\nThe `language` parameter affects the names of controls, copyright\nnotices, driving directions, and control labels, as well as the responses to\nservice requests. The effect on services is not as apparent. For example, when\ngeocoding street level addresses the country name is returned in the language\nyou requested, but the rest of the address will be specific to the location\nyou are geocoding. On the other hand, postal and political results are\nreturned in the requested language.\nTry [this demo](/maps/documentation/javascript/demos/localization) to experiment with the changes on the map when you update the\n`language` parameter.\n\nThe following example displays a map in Japanese and sets the region to\nJapan: \n\n```html\n\u003cscript async\n src=\"https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async®ion=JP&language=ja&callback=initMap\"\u003e\n\u003c/script\u003e\n```\n\n[View\nexample](/maps/documentation/javascript/examples/map-language).\n\nIf you set the language of the map, it's important to\nconsider setting the [region](#Region) too. This helps ensure\nthat your application complies with local laws.\n\n**Note:** When you load the API in the manner shown above, the\nmap uses the Japanese language for all users regardless of user preferences.\nBe sure you want this behavior before setting this option.\n\nThe Maps JavaScript API also supports bi-directional\n(Bidi) text containing characters in both left-to-right (LTR) and\nright-to-left (RTL) languages natively. Examples of RTL languages include\nArabic, Hebrew, and Farsi. Generally, you should specify RTL language pages to\nrender properly by adding `dir='rtl'` to the page's\n`\u003chtml\u003e` element. The following example renders a map of\nCairo, Egypt using Arabic controls: \n\n```html\n\u003cscript async\n src=\"https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async®ion=EG&language=ar&callback=initMap\"\u003e\n\u003c/script\u003e\n```\n\n[View example](/maps/documentation/javascript/examples/map-rtl)\n\nSee the [list of supported\nlanguages](/maps/faq#languagesupport). Note that new languages are added often, so this list may not\nbe exhaustive.\n\nRegion localization\n\nAdd a `region` parameter to the `\u003cscript\u003e` tag\nwhen loading the Maps JavaScript API code, if you\nwant to alter your application to serve different map tiles or bias the\napplication (such as biasing geocoding results towards the region).\n\nAs the developer of a Maps JavaScript API\napplication you are encouraged to always set a `region` parameter as various services\n(such as Places Autocomplete) tend to provide better results when the `region` is set.\nIt is also your responsibility to ensure that your application complies with local laws by\nensuring that the correct region localization is applied for the country in which the application\nis hosted.\n\nThe `region` parameter accepts\n[Unicode region subtag identifiers](http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) which (generally) have a\none-to-one mapping to country code Top-Level Domains (ccTLDs). Most Unicode\nregion identifiers are identical to ISO 3166-1 alpha-2 codes, with some\nnotable exceptions. For example, Great Britain's ccTLD is \"uk\" (corresponding\nto the domain `.co.uk`) while its region identifier is \"GB.\" See\n[Google Maps Platform Coverage Details](/maps/coverage) for\nsupported regions.\nTry [this demo](/maps/documentation/javascript/demos/localization) to experiment with the changes on the map when you update the\n`region` parameter.\n\nFor example, the following script tag localizes the map to the United\nKingdom: \n\n```html\n\u003cscript async\n src=\"https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async®ion=GB&callback=initMap\"\u003e\n\u003c/script\u003e\n```\n\nThe following examples show two maps, one which geocodes \"Toledo\" based on\na `region` set to `US` (US) to \"Toledo, Ohio\" and one\nwhich biases results based on a `region` set to `ES`\n(Spain) to \"Toledo, Spain.\" \n\nView the\n[US\nexample](/maps/documentation/javascript/examples/geocoding-region-us) and the\n[ES\nexample](/maps/documentation/javascript/examples/geocoding-region-es).\n\nLocalization Demo\n\nWhen setting the language of the map, it's important to consider setting the region too.\nHere is a demo that allows you to load the map with your choice of language and region.\n\nView this demo in [fullscreen](/maps/documentation/javascript/demos/localization)."]]