Google Maps - Localization
Google Maps - Localization
Section titled “Google Maps - Localization”By default, Google Maps displays place names, labels, and UI controls in the user’s preferred language setting (often determined by browser settings) or English. Localization allows you to explicitly set the language and regional formatting for your map.
Why Localize?
Section titled “Why Localize?”- User Experience: Presenting the map in the user’s native language improves usability and comfort.
- Consistency: Ensures the map language matches the language of your website or application.
- Regional Relevance: Can influence how certain boundaries or place names are displayed based on regional perspectives (using the
regionparameter).
How to Localize
Section titled “How to Localize”Localization is configured when you load the Maps JavaScript API by adding parameters to the script URL:
languageParameter: Specifies the language to use for labels, controls, and textual information. Uses BCP 47 language codes (e.g.,jafor Japanese,esfor Spanish,zh-CNfor Simplified Chinese).regionParameter: Specifies a regional bias (optional). Uses two-character ISO 3166-1 Alpha-2 country codes (e.g.,JPfor Japan,ESfor Spain,CNfor China). This primarily affects:-
- How map tiles are biased towards features within that region.
-
- Behavior of applications using external services like Geocoding (biases results towards the region).
Example: Loading the API for Japanese Language (ja) in Japan (JP)
Section titled “Example: Loading the API for Japanese Language (ja) in Japan (JP)”<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&v=weekly&language=ja®ion=JP" async defer></script>Example: Loading the API for Spanish Language (es) without specific region bias
Section titled “Example: Loading the API for Spanish Language (es) without specific region bias”<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&v=weekly&language=es" async defer></script>Supported Languages
Section titled “Supported Languages”Google Maps supports a wide range of languages. Refer to the official documentation for the complete, up-to-date list:
If a language is specified but not fully supported for map tiles in a specific area, the API may fall back to a closely related language or the default (English).
Example: Displaying a Map Localized to Chinese (Simplified)
Section titled “Example: Displaying a Map Localized to Chinese (Simplified)”This example loads a map centered on Beijing, explicitly requesting Simplified Chinese language and the China region.
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Localized Map (Chinese)</title> <style>#map { height: 400px; width: 100%; } html, body { height: 100%; margin: 0; padding: 0; }</style></head><body> <div id="map"></div> <script> async function initMap() { const position = { lat: 39.9042, lng: 116.4074 }; // Beijing const { Map } = await google.maps.importLibrary("maps");
const map = new Map(document.getElementById("map"), { center: position, zoom: 11, mapId: "DEMO_MAP_ID", mapTypeId: 'roadmap' }); } </script> <!-- Load API with language and region --> <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&v=weekly&language=zh-CN®ion=CN" async defer></script></body></html>Expected Output: A map of Beijing where place names (like ‘北京市’), UI controls (like zoom buttons), and copyright information appear in Simplified Chinese.
Important Considerations
Section titled “Important Considerations”- Right-to-Left (RTL) Languages: The API automatically handles layout adjustments for RTL languages like Arabic (
ar) or Hebrew (iw) when specified. - Content: Localization only affects text provided by Google (labels, controls). Any custom content you add (e.g., in InfoWindows) needs to be translated separately within your application.
- Testing: Always test your chosen language/region combination to ensure it behaves as expected, especially regarding place names and regional nuances.